From 50f1aff778822ec94fe7e0521c6f80a8886a003f Mon Sep 17 00:00:00 2001 From: Borys Piddubnyi Date: Fri, 21 Oct 2016 15:40:53 +0300 Subject: [PATCH] Fix "invalid expire time in set" for SetXX with expiration = 0 --- commands.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 8a2b9c5d..b1510b06 100644 --- a/commands.go +++ b/commands.go @@ -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