From 01443d44083b0c31b0b3d1b96eaf34cfb08beaeb Mon Sep 17 00:00:00 2001 From: Zeng Ke Date: Mon, 27 May 2024 20:07:35 +0800 Subject: [PATCH] v0.4.2, consider the case when m.cfg is nil --- core/redisutil.go | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/core/redisutil.go b/core/redisutil.go index 2abe999..eb96beb 100644 --- a/core/redisutil.go +++ b/core/redisutil.go @@ -41,15 +41,17 @@ func (m *Multiplexer) RedisClient(selector string) (c *redis.Client, ok bool) { return c, ok } - if store, ok := m.cfg.Stores[selector]; ok && store.Scheme() == "redis" { - opts, err := GetRedisOptions(store.Url) - if err != nil { - log.Panicf("parse redis option error, url=%s, %s", store.Url, err) - return nil, false + if m.cfg != nil && m.cfg.Stores != nil { + if store, ok := m.cfg.Stores[selector]; ok && store.Scheme() == "redis" { + opts, err := GetRedisOptions(store.Url) + if err != nil { + log.Panicf("parse redis option error, url=%s, %s", store.Url, err) + return nil, false + } + c := redis.NewClient(opts) + m.redisClients[selector] = c + return c, true } - c := redis.NewClient(opts) - m.redisClients[selector] = c - return c, true } if selector != "default" { @@ -63,16 +65,17 @@ func (m *Multiplexer) RedisClientExact(selector string) (c *redis.Client, ok boo if c, ok := m.redisClients[selector]; ok { return c, ok } - - if store, ok := m.cfg.Stores[selector]; ok && store.Scheme() == "redis" { - opts, err := GetRedisOptions(store.Url) - if err != nil { - log.Panicf("parse redis option error, url=%s, %s", store.Url, err) - return nil, false + if m.cfg != nil && m.cfg.Stores != nil { + if store, ok := m.cfg.Stores[selector]; ok && store.Scheme() == "redis" { + opts, err := GetRedisOptions(store.Url) + if err != nil { + log.Panicf("parse redis option error, url=%s, %s", store.Url, err) + return nil, false + } + c := redis.NewClient(opts) + m.redisClients[selector] = c + return c, true } - c := redis.NewClient(opts) - m.redisClients[selector] = c - return c, true } return nil, false