diff --git a/hack/cmds/commands.json b/hack/cmds/commands.json index e832e1b..bfdd20d 100644 --- a/hack/cmds/commands.json +++ b/hack/cmds/commands.json @@ -5050,10 +5050,23 @@ }, { "name": "condition", - "type": "enum", - "enum": [ - "NX", - "XX" + "type": "oneof", + "arguments": [ + { + "name": "nx", + "type": "pure-token", + "token": "NX" + }, + { + "name": "xx", + "type": "pure-token", + "token": "XX" + }, + { + "name": "ifeq", + "type": "string", + "token": "IFEQ" + } ], "optional": true }, diff --git a/internal/cmds/gen_string.go b/internal/cmds/gen_string.go index 6b56626..959789d 100644 --- a/internal/cmds/gen_string.go +++ b/internal/cmds/gen_string.go @@ -729,6 +729,63 @@ func (c Set) Key(key string) SetKey { return (SetKey)(c) } +type SetConditionIfeq Incomplete + +func (c SetConditionIfeq) Get() SetGet { + c.cs.s = append(c.cs.s, "GET") + return (SetGet)(c) +} + +func (c SetConditionIfeq) ExSeconds(seconds int64) SetExpirationExSeconds { + c.cs.s = append(c.cs.s, "EX", strconv.FormatInt(seconds, 10)) + return (SetExpirationExSeconds)(c) +} + +func (c SetConditionIfeq) PxMilliseconds(milliseconds int64) SetExpirationPxMilliseconds { + c.cs.s = append(c.cs.s, "PX", strconv.FormatInt(milliseconds, 10)) + return (SetExpirationPxMilliseconds)(c) +} + +func (c SetConditionIfeq) ExatTimestamp(timestamp int64) SetExpirationExatTimestamp { + c.cs.s = append(c.cs.s, "EXAT", strconv.FormatInt(timestamp, 10)) + return (SetExpirationExatTimestamp)(c) +} + +func (c SetConditionIfeq) PxatMillisecondsTimestamp(millisecondsTimestamp int64) SetExpirationPxatMillisecondsTimestamp { + c.cs.s = append(c.cs.s, "PXAT", strconv.FormatInt(millisecondsTimestamp, 10)) + return (SetExpirationPxatMillisecondsTimestamp)(c) +} + +func (c SetConditionIfeq) Keepttl() SetExpirationKeepttl { + c.cs.s = append(c.cs.s, "KEEPTTL") + return (SetExpirationKeepttl)(c) +} + +func (c SetConditionIfeq) Ex(duration time.Duration) SetExpirationExSecTyped { + c.cs.s = append(c.cs.s, "EX", strconv.FormatInt(int64(duration/time.Second), 10)) + return (SetExpirationExSecTyped)(c) +} + +func (c SetConditionIfeq) Px(duration time.Duration) SetExpirationPxMsTyped { + c.cs.s = append(c.cs.s, "PX", strconv.FormatInt(int64(duration/time.Millisecond), 10)) + return (SetExpirationPxMsTyped)(c) +} + +func (c SetConditionIfeq) Exat(timestamp time.Time) SetExpirationExatTimestampTyped { + c.cs.s = append(c.cs.s, "EXAT", strconv.FormatInt(timestamp.Unix(), 10)) + return (SetExpirationExatTimestampTyped)(c) +} + +func (c SetConditionIfeq) Pxat(timestamp time.Time) SetExpirationPxatMsTimestampTyped { + c.cs.s = append(c.cs.s, "PXAT", strconv.FormatInt(timestamp.UnixMilli(), 10)) + return (SetExpirationPxatMsTimestampTyped)(c) +} + +func (c SetConditionIfeq) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + type SetConditionNx Incomplete func (c SetConditionNx) Get() SetGet { @@ -977,6 +1034,11 @@ func (c SetValue) Xx() SetConditionXx { return (SetConditionXx)(c) } +func (c SetValue) Ifeq(ifeq string) SetConditionIfeq { + c.cs.s = append(c.cs.s, ifeq) + return (SetConditionIfeq)(c) +} + func (c SetValue) Get() SetGet { c.cs.s = append(c.cs.s, "GET") return (SetGet)(c) diff --git a/internal/cmds/gen_string_test.go b/internal/cmds/gen_string_test.go index 1769ded..e816443 100644 --- a/internal/cmds/gen_string_test.go +++ b/internal/cmds/gen_string_test.go @@ -77,6 +77,17 @@ func string0(s Builder) { s.Set().Key("1").Value("1").Xx().Exat(time.Now()).Build() s.Set().Key("1").Value("1").Xx().Pxat(time.Now()).Build() s.Set().Key("1").Value("1").Xx().Build() + s.Set().Key("1").Value("1").Ifeq("1").Get().Build() + s.Set().Key("1").Value("1").Ifeq("1").ExSeconds(1).Build() + s.Set().Key("1").Value("1").Ifeq("1").PxMilliseconds(1).Build() + s.Set().Key("1").Value("1").Ifeq("1").ExatTimestamp(1).Build() + s.Set().Key("1").Value("1").Ifeq("1").PxatMillisecondsTimestamp(1).Build() + s.Set().Key("1").Value("1").Ifeq("1").Keepttl().Build() + s.Set().Key("1").Value("1").Ifeq("1").Ex(time.Second).Build() + s.Set().Key("1").Value("1").Ifeq("1").Px(time.Second).Build() + s.Set().Key("1").Value("1").Ifeq("1").Exat(time.Now()).Build() + s.Set().Key("1").Value("1").Ifeq("1").Pxat(time.Now()).Build() + s.Set().Key("1").Value("1").Ifeq("1").Build() s.Set().Key("1").Value("1").Get().Build() s.Set().Key("1").Value("1").ExSeconds(1).Build() s.Set().Key("1").Value("1").PxMilliseconds(1).Build()