| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package rediscli
- import (
- "encoding/hex"
- "fmt"
- "mtp2_if/config"
- "mtp2_if/packet"
- "github.com/go-redis/redis"
- )
- var RedisCli *redis.Client
- func InitRedisCli() error {
- // 尝试解密
- var dbPwd []byte
- ciphertext, _ := hex.DecodeString(config.SerCfg.GetRedisPwd())
- if len(ciphertext) > 8 {
- ciphertext = ciphertext[4 : len(ciphertext)-8]
- dbPwd, _ = packet.Decrypt(ciphertext, packet.AESKey, true)
- if dbPwd == nil {
- dbPwd = []byte(config.SerCfg.GetRedisPwd())
- }
- } else {
- dbPwd = []byte(config.SerCfg.GetRedisPwd())
- }
- RedisCli = redis.NewClient(&redis.Options{
- Addr: config.SerCfg.GetRedisAddress(),
- Password: string(dbPwd),
- DB: config.SerCfg.GetRedisDbNum(),
- PoolSize: config.SerCfg.GetRedisConnNum(),
- })
- pong, err := RedisCli.Ping().Result()
- if err != nil {
- fmt.Println(pong, err)
- return err
- }
- return nil
- }
- func GetRedisClient() *redis.Client {
- return RedisCli
- }
- func CloseReidsClient() {
- RedisCli.Close()
- }
|