MCPcopy
hub / github.com/redis/go-redis / SetIFEQGet

Method SetIFEQGet

string_commands.go:686–704  ·  view source on GitHub ↗

SetIFEQGet Redis `SET key value [expiration] IFEQ match-value GET` command. Compare-and-set with GET: only sets the value if the current value equals matchValue, and returns the previous value. Returns the previous value on success. Returns nil if the operation was aborted due to condition not matc

(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration)

Source from the content-addressed store, hash-verified

684// NOTE SetIFEQGet is still experimental
685// it's signature and behaviour may change
686func (c cmdable) SetIFEQGet(ctx context.Context, key string, value interface{}, matchValue interface{}, expiration time.Duration) *StringCmd {
687 args := []interface{}{"set", key, value}
688
689 if expiration > 0 {
690 if usePrecise(expiration) {
691 args = append(args, "px", formatMs(ctx, expiration))
692 } else {
693 args = append(args, "ex", formatSec(ctx, expiration))
694 }
695 } else if expiration == KeepTTL {
696 args = append(args, "keepttl")
697 }
698
699 args = append(args, "ifeq", matchValue, "get")
700
701 cmd := NewStringCmd(ctx, args...)
702 _ = c(ctx, cmd)
703 return cmd
704}
705
706// SetIFNE Redis `SET key value [expiration] IFNE match-value` command.
707// Compare-and-set: only sets the value if the current value does not equal matchValue.

Callers

nothing calls this directly

Calls 4

usePreciseFunction · 0.85
formatMsFunction · 0.85
formatSecFunction · 0.85
NewStringCmdFunction · 0.85

Tested by

no test coverage detected