You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.6 KiB
41 lines
1.6 KiB
package confignosql
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
type RedisSetUp struct {
|
|
MasterRedis RedisConfitSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库
|
|
MasterRedis1 RedisConfitSetUp `mapstructure:"master1" json:"master1" yaml:"master1"` //主数据库
|
|
MasterRedis2 RedisConfitSetUp `mapstructure:"master2" json:"master1" yaml:"master2"` //主数据库
|
|
MasterRedis3 RedisConfitSetUp `mapstructure:"master3" json:"master1" yaml:"master3"` //主数据库
|
|
MasterRedis4 RedisConfitSetUp `mapstructure:"master4" json:"master1" yaml:"master4"` //主数据库
|
|
MasterRedis5 RedisConfitSetUp `mapstructure:"master5" json:"master1" yaml:"master5"` //主数据库
|
|
}
|
|
|
|
type RedisConfitSetUp struct {
|
|
UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址
|
|
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
|
Name int `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称
|
|
PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
|
}
|
|
|
|
func (r *RedisConfitSetUp) OpenRedis() *redis.Client {
|
|
address := fmt.Sprintf("%v:%v", r.UrlPath, r.Port)
|
|
fmt.Printf("开启%v Redis库 %v\n", address, r.Name)
|
|
redisClient := redis.NewClient(&redis.Options{
|
|
Addr: address,
|
|
Password: r.PassWord,
|
|
DB: r.Name,
|
|
})
|
|
pingLink, err := redisClient.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
fmt.Printf("%v Redis链接失败!原因:%v\n", r.Name, err)
|
|
} else {
|
|
fmt.Printf("%v Redis链接成功!=====>%v\n", r.Name, pingLink)
|
|
}
|
|
return redisClient
|
|
}
|
|
|