Commit 25a3683c authored by Akshay Bharambe's avatar Akshay Bharambe
Browse files

Add: Check redis connection on setup

1. Add: Check redis connection on setup
parent 73ec22a0
Branches
Tags
2 merge requests!134Mep release271219,!130Add: Redis as a cache to support grid mode
Showing with 10 additions and 2 deletions
......@@ -13,7 +13,7 @@ const (
)
var (
// ErrInvalidCacheType indicates provided cache type is not supportd
// ErrInvalidCacheType indicates provided cache type is not supported
ErrInvalidCacheType = errors.New("invalid cache type provided")
)
......@@ -44,7 +44,7 @@ func GetCacheInstance(cfg *CacheConfig) Cacher {
return cfg.FastCache
case TypeRedisCache:
cfg.RedisCache.Setup(cfg.RedisCache.Addr, cfg.RedisCache.Password, "", cfg.RedisCache.DB, cfg.RedisCache.Expiration)
cfg.RedisCache.Setup(cfg.RedisCache.Addr, cfg.RedisCache.Password, cfg.RedisCache.Prefix, cfg.RedisCache.DB, cfg.RedisCache.Expiration)
return cfg.RedisCache
default:
......
......@@ -42,6 +42,7 @@ type RedisCache struct {
opt *redis.Options //
keyStr string // "<Prefix>:"
addPrefix bool //
connected bool // will be enabled if redis client connects to server
Addr string // redis server address, default "127.0.0.1:6379"
DB int // redis DB on provided server, default 0
......@@ -69,6 +70,13 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
rc.opt = &opt
rc.cli = redis.NewClient(&opt)
if _, err := rc.cli.Ping().Result(); err != nil {
loggermdl.LogError("connection to redis server failed: ", err)
} else {
rc.connected = true
}
if prefix != "" {
rc.keyStr = contcat(rc.Prefix, keySplitter)
rc.addPrefix = true
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment