1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package parser
- import (
- "fmt"
- "smart-log/config"
- "github.com/jaryhe/gopkgs/cache"
- )
- var redisConfig config.RedisConfig
- func RedisHandler(conf *config.Configure) {
- // redisConfig.Addr 不为空表示已经初始化
- if len(redisConfig.Addrs) != 0 {
- // 地址或密码变化,关闭当前连接,重新连接
- if len(redisConfig.Addrs) != len(conf.Redis.Addrs) ||
- redisConfig.Password != conf.Redis.Password {
- cache.Close()
- } else {
- // 判断addrs数组是否相同
- addrs := map[string]bool{}
- for _, v := range redisConfig.Addrs {
- addrs[v] = true
- }
- for _, v := range conf.Redis.Addrs {
- addrs[v] = true
- }
- // 地址和密码不变返回
- if len(redisConfig.Addrs) == len(addrs) {
- return
- }
- // 关闭cache
- cache.Close()
- }
- }
- // 私有db不合法使用公共db
- db := conf.Rpc.SmartLog.RedisDb
- if db < 0 || db > 15 {
- db = conf.Redis.DB
- }
- fmt.Println("db :", db, conf.Redis)
- // 连接redis
- cache.Setup(conf.Redis.Addrs,
- conf.Redis.Password,
- db,
- conf.Redis.PoolSize,
- conf.Redis.MinIdleConns,
- conf.Redis.MaxRetries,
- conf.Redis.Cluster)
- if conf.RunMode != "prod" {
- // open 'DEBUG' switcher
- }
- redisConfig = conf.Redis
- }
|