setnx
SETNX
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Store
Stores the value only if the same key does not already exist in the database.
Usage is setnx key value.
Example
| Command> | setnx key Hello |
| Result> | 1 |
| Command> | setnx key Redis |
| Result> | 0 store failed because data already exists for the key |
| Command> | get key |
| Result> | Hello the first stored value Hello is returned. |
![]() |
This command behaves the same as set key value NX. |
|---|
Syntax
SETNX key value
- Available since version 1.0.0.
- Time complexity is O(1).
| Related commands | SET, MSETNX |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << INCRBYFLOAT | SETNX | SETEX >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.

