Skip to content

ERR wrong number of arguments for 'setnx' command #2751

Closed

Description

@flamewave

When calling IDatabase.StringSet with when=When.NotExists and keepTtl=true, you are calling the "SETNX" command and also passing the KEEPTTL option, which is not supported. This should be updated to use the "SET" command with the "NX" and "KEEPTTL" options instead.

Example call:
IDatabase db = ...;
bool result = db.StringSet("key", "value", null, true, When.NotExists);

When.NotExists when keepTtl => Message.Create(Database, flags, RedisCommand.SETNX, key, value, RedisLiterals.KEEPTTL),

Activity

  1. self-assigned this
    on Jun 27, 2024
  2. mgravell commented on Jul 22, 2026

    @mgravell
    Collaborator

    Fixed in StackExchange.Redis 2.10.1 (#2977): StringSet with When.NotExists + keepTtl:true no longer emits an invalid SETNX … KEEPTTL; it issues a plain SETNX (equivalent — a non-existent key has no TTL). Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions