Available since 1.0.0.

SETNX key value

Set key to hold string value if key does not exist. In that case, it is equal to SET. When key already holds a value, no operation is performed. SETNX is short for "SET if Not eXists".

Return value

Integer reply, specifically:

  • 1 if the key was set
  • 0 if the key was not set

Examples

redis> SETNX mykey "Hello"
(integer) 1
redis> SETNX mykey "World"
(integer) 0
redis> GET mykey
"Hello"
redis>

Hierarchy

Constructors

Properties

blocking?: boolean
dataType?: DataType

Used for "database" commands to enforce type checking.

dbDataType: DataType = DataType.STRING
logger: Logger = ...
maxParams: number = 2

Maximum number of parameters allowed. -1 for no maximum.

minParams: number = 2

Minimum number of parameters require.

name: string = "setnx"
pubSubAllowed?: boolean

Used when PUB/SUB is in effect.

sign?: number

Sign is used in commands with a compliment command. The only current example is INCR/DECR. Sign is 1 for INCR and -1 for DECR

txIgnore?: boolean

Used in transactions to enqueue a command.

Methods