Skip to content

Deprecation of SetNX causes inconvinienve (BoolCmd Vs StatusCmd) #3715

@astj

Description

@astj

At 9.18.0, by #3673, cmdable.SetNX is marked as deprecated (along with other old commands).
The deprecation notice says Use Set with NX option instead as of Redis 2.6.12.. But in go-redis, SetNX is provided as BoolCmd but Set is as StatusCmd, so they are not equivalent.
Especially my codebase uses SetNX to acquire lock, like lockAcquired, err := rdb.SetNX(...) , so changing it to cmdable.Set is not straight-forward.

(In contrast, cmdable.SetEx, which is also deprecated in #3673 , is perfectly safe to deprecate since it's interface is same as cmdable.Set)

Expected Behavior

There're (convenient) ways to use SET NX operation as BoolCmd

Current Behavior

SetNX is deprecated, and Set is StatusCmd and is not BoolCmd

Possible Solution

No idea?

For me un-deprecate cmdable.SetNX seems fine.
Additionally, by removing old setnx fallback, it will be "clean" since it will not use old redis commands anymore.

go-redis/string_commands.go

Lines 440 to 442 in 90faf06

case 0:
// Use old `SETNX` to support old Redis versions.
cmd = NewBoolCmd(ctx, "setnx", key, value)

But, if you'd like remove cmdable.SetNX itself in future, maybe it's not good one.

Steps to Reproduce

Context (Environment)

Detailed Description

Possible Implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions