From ef36ecd376b982af7c36a210bb388abd1d1c614e Mon Sep 17 00:00:00 2001 From: zhufanmao Date: Thu, 31 Aug 2017 20:26:32 +0800 Subject: [PATCH] avoid some proxy not support select command --- session/redis/sess_redis.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index d0424515..55595851 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -160,10 +160,13 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error { return nil, err } } - _, err = c.Do("SELECT", rp.dbNum) - if err != nil { - c.Close() - return nil, err + //some redis proxy such as twemproxy is not support select command + if rp.dbNum > 0 { + _, err = c.Do("SELECT", rp.dbNum) + if err != nil { + c.Close() + return nil, err + } } return c, err }, rp.poolsize)