From d9f1dc2386f0324418a3aa10af2bef4133b58a25 Mon Sep 17 00:00:00 2001 From: "Giovanni T. Parra" Date: Fri, 24 Feb 2017 22:01:11 -0300 Subject: [PATCH 1/3] Mention SETEX in the documentation. To help people looking for it specifically. --- commands.go | 1 + 1 file changed, 1 insertion(+) diff --git a/commands.go b/commands.go index e2dc0ca..b96da7b 100644 --- a/commands.go +++ b/commands.go @@ -734,6 +734,7 @@ func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd { // Redis `SET key value [expiration]` command. // +// Use expiration for `SETEX`-like behavior. // Zero expiration means the key has no expiration time. func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd { args := make([]interface{}, 3, 4) From 518c1051693a15326f82e764722facf6d025b4c7 Mon Sep 17 00:00:00 2001 From: Yin Jifeng Date: Wed, 1 Mar 2017 22:41:18 +0800 Subject: [PATCH 2/3] StringCmd: remove an unnessary type casting this fixes up 69554c0e --- command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.go b/command.go index e28eb75..8ad982b 100644 --- a/command.go +++ b/command.go @@ -445,7 +445,7 @@ func (cmd *StringCmd) Result() (string, error) { } func (cmd *StringCmd) Bytes() ([]byte, error) { - return []byte(cmd.val), cmd.err + return cmd.val, cmd.err } func (cmd *StringCmd) Int64() (int64, error) { From 216ec11a0e8175294eb2f983ef73bbe94be6d7ec Mon Sep 17 00:00:00 2001 From: yuekui Date: Fri, 3 Mar 2017 15:45:40 -0800 Subject: [PATCH 3/3] Fix wrong usage of timer Reset(), which could cause service frozen during master switch. --- internal/pool/pool.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 4033e58..c97875f 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -19,7 +19,9 @@ var ( var timers = sync.Pool{ New: func() interface{} { - return time.NewTimer(0) + t := time.NewTimer(time.Hour) + t.Stop() + return t }, } @@ -95,12 +97,13 @@ func (p *ConnPool) NewConn() (*Conn, error) { func (p *ConnPool) PopFree() *Conn { timer := timers.Get().(*time.Timer) - if !timer.Reset(p.poolTimeout) { - <-timer.C - } + timer.Reset(p.poolTimeout) select { case p.queue <- struct{}{}: + if !timer.Stop() { + <-timer.C + } timers.Put(timer) case <-timer.C: timers.Put(timer) @@ -138,12 +141,13 @@ func (p *ConnPool) Get() (*Conn, bool, error) { atomic.AddUint32(&p.stats.Requests, 1) timer := timers.Get().(*time.Timer) - if !timer.Reset(p.poolTimeout) { - <-timer.C - } + timer.Reset(p.poolTimeout) select { case p.queue <- struct{}{}: + if !timer.Stop() { + <-timer.C + } timers.Put(timer) case <-timer.C: timers.Put(timer)