1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Merge pull request #409 from bpiddubnyi/bugfix/setxx-zero-ex

Fix "invalid expire time in set" for SetXX with expiration = 0
This commit is contained in:
Vladimir Mihailenco
2016-10-24 12:52:32 +03:00
committed by GitHub
2 changed files with 24 additions and 3 deletions

View File

@ -788,10 +788,14 @@ 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 usePrecise(expiration) {
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx")
if expiration == 0 {
cmd = NewBoolCmd("set", key, value, "xx")
} else {
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx")
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