From 744ff208ff1b3b4c35347f7f5fd588f3a20521c4 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Thu, 26 Feb 2026 16:26:50 +0200 Subject: [PATCH] fix(setnx): use set with nx instead setnx --- string_commands.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/string_commands.go b/string_commands.go index f69d3d053..609a9541d 100644 --- a/string_commands.go +++ b/string_commands.go @@ -429,8 +429,6 @@ func (c cmdable) SetEx(ctx context.Context, key string, value interface{}, expir // SetNX sets the value of a key only if the key does not exist. // -// Deprecated: Use Set with NX option instead as of Redis 2.6.12. -// // Zero expiration means the key has no expiration time. // KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0, // otherwise you will receive an error: (error) ERR syntax error. @@ -438,8 +436,7 @@ func (c cmdable) SetNX(ctx context.Context, key string, value interface{}, expir var cmd *BoolCmd switch expiration { case 0: - // Use old `SETNX` to support old Redis versions. - cmd = NewBoolCmd(ctx, "setnx", key, value) + cmd = NewBoolCmd(ctx, "set", key, value, "nx") case KeepTTL: cmd = NewBoolCmd(ctx, "set", key, value, "keepttl", "nx") default: