65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
|
||
|
redis "gopkg.in/redis.v4"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
RedisFifteen *redis.Client
|
||
|
Redis0 *redis.Client
|
||
|
Redis4 *redis.Client
|
||
|
Redis5 *redis.Client
|
||
|
Redis7 *redis.Client
|
||
|
Redis8 *redis.Client
|
||
|
)
|
||
|
|
||
|
// InitRedisEight 连接reids
|
||
|
func InitRedisEight(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
// InitRedisFifteen 连接reids
|
||
|
func InitRedisFifteen(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
func InitRedis0(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
func InitRedis4(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
func InitRedis5(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
func InitRedis7(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
func InitRedis8(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
return initRedis(addr, pwd, db, coon)
|
||
|
}
|
||
|
|
||
|
func initRedis(addr string, pwd string, db int, coon int) (*redis.Client, error) {
|
||
|
|
||
|
red := redis.NewClient(&redis.Options{
|
||
|
Addr: addr,
|
||
|
Password: pwd,
|
||
|
DB: db,
|
||
|
PoolSize: coon,
|
||
|
})
|
||
|
|
||
|
_, err := red.Ping().Result()
|
||
|
if nil != err {
|
||
|
red.Close()
|
||
|
return nil, errors.New(fmt.Sprintf("fail to ping redis,addr :%s , pwd :%s ,DB :%d", addr, pwd, db))
|
||
|
}
|
||
|
|
||
|
return red, nil
|
||
|
}
|