From b1102bda0d54b7323bd46ffe2126a5658dc833f5 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 19 Jun 2024 15:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86redis=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 1 + config/redis.go | 1 + core/redis.go | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index e0ceaa1..92dc6c2 100644 --- a/config.yaml +++ b/config.yaml @@ -25,6 +25,7 @@ redis: port: 30002 password: gdxz2022&dj. pool-size: 100 + db: 1 # [jwt] jwt: diff --git a/config/redis.go b/config/redis.go index bcc47b9..324aaba 100644 --- a/config/redis.go +++ b/config/redis.go @@ -5,4 +5,5 @@ type Redis struct { Port int `mapstructure:"port" json:"port" yaml:"port"` // 服务器端口 Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码 PoolSize int `mapstructure:"pool-size" json:"pool-size" yaml:"pool-size"` // 连接池大小 + Db int `mapstructure:"db" json:"db" yaml:"db"` // 数据库 } diff --git a/core/redis.go b/core/redis.go index 6d7d603..f4bda1f 100644 --- a/core/redis.go +++ b/core/redis.go @@ -14,7 +14,7 @@ func Redis() { global.Redis = redis.NewClient(&redis.Options{ Addr: config.C.Redis.Host + ":" + strconv.Itoa(config.C.Redis.Port), Password: config.C.Redis.Password, // no password set - DB: 0, // use default DB + DB: config.C.Redis.Db, // use default DB PoolSize: config.C.Redis.PoolSize, }) _, err := global.Redis.Ping(context.Background()).Result()