forked from mirror/redis
Merge branch 'v5'
This commit is contained in:
commit
bb270e3277
|
@ -445,7 +445,7 @@ func (cmd *StringCmd) Result() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *StringCmd) Bytes() ([]byte, error) {
|
func (cmd *StringCmd) Bytes() ([]byte, error) {
|
||||||
return []byte(cmd.val), cmd.err
|
return cmd.val, cmd.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *StringCmd) Int64() (int64, error) {
|
func (cmd *StringCmd) Int64() (int64, error) {
|
||||||
|
|
|
@ -726,6 +726,7 @@ func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd {
|
||||||
|
|
||||||
// Redis `SET key value [expiration]` command.
|
// Redis `SET key value [expiration]` command.
|
||||||
//
|
//
|
||||||
|
// Use expiration for `SETEX`-like behavior.
|
||||||
// Zero expiration means the key has no expiration time.
|
// Zero expiration means the key has no expiration time.
|
||||||
func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
|
func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
|
||||||
args := make([]interface{}, 3, 4)
|
args := make([]interface{}, 3, 4)
|
||||||
|
|
|
@ -19,7 +19,9 @@ var (
|
||||||
|
|
||||||
var timers = sync.Pool{
|
var timers = sync.Pool{
|
||||||
New: func() interface{} {
|
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 {
|
func (p *ConnPool) PopFree() *Conn {
|
||||||
timer := timers.Get().(*time.Timer)
|
timer := timers.Get().(*time.Timer)
|
||||||
if !timer.Reset(p.poolTimeout) {
|
timer.Reset(p.poolTimeout)
|
||||||
<-timer.C
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case p.queue <- struct{}{}:
|
case p.queue <- struct{}{}:
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
timers.Put(timer)
|
timers.Put(timer)
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
timers.Put(timer)
|
timers.Put(timer)
|
||||||
|
@ -138,12 +141,13 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
|
||||||
atomic.AddUint32(&p.stats.Requests, 1)
|
atomic.AddUint32(&p.stats.Requests, 1)
|
||||||
|
|
||||||
timer := timers.Get().(*time.Timer)
|
timer := timers.Get().(*time.Timer)
|
||||||
if !timer.Reset(p.poolTimeout) {
|
timer.Reset(p.poolTimeout)
|
||||||
<-timer.C
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case p.queue <- struct{}{}:
|
case p.queue <- struct{}{}:
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
timers.Put(timer)
|
timers.Put(timer)
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
timers.Put(timer)
|
timers.Put(timer)
|
||||||
|
|
Loading…
Reference in New Issue