Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Redis String: SETNX key value

SETNX key value

Redis SETNX command is used to set some string value in redis key, if the key does not exist in redis. When key already holds a value, no operation is performed. SETNX is short for "SET if Not eXists".

Syntax:

SETNX KEY_NAME VALUE

Available since

1.0.0.

Return Value

Integer replies 1 or 0

  • 1, if the key is set.
  • 0, if the key is not set.

Return Value Type

Integer

Example: Redis SETNX

redis 127.0.0.1:6379> SETNX mykey redis
(integer) 1
redis 127.0.0.1:6379> SETNX mykey mongodb
(integer) 0
redis 127.0.0.1:6379> GET mykey
"redis"

Previous: SETEX
Next: SETRANGE