Fix "invalid expire time in set" for SetXX with expiration = 0

This commit is contained in:
Borys Piddubnyi 2016-10-21 15:40:53 +03:00
parent 6f8957c5b7
commit 50f1aff778
1 changed files with 7 additions and 3 deletions

View File

@ -788,11 +788,15 @@ func (c *cmdable) SetNX(key string, value interface{}, expiration time.Duration)
// Zero expiration means the key has no expiration time.
func (c *cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
var cmd *BoolCmd
if expiration == 0 {
cmd = NewBoolCmd("set", key, value, "xx")
} else {
if usePrecise(expiration) {
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx")
} else {
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx")
}
}
c.process(cmd)
return cmd
}