English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Redis Setnx (SET if Not eXThe SET command sets the value of the specified key. If the key does not exist, it is created.
The basic syntax of the Redis Setnx command is as follows:
redis 127.0.0.1:6379> SETNX KEY_NAME VALUE
>= 1.0.0
Setting successful, return 1 . Setting failed, return 0 .
redis> EXISTS job # job does not exist (integer) 0 redis> SETNX job "programmer" # job set successfully (integer) 1 redis> SETNX job "code-farmer" # Attempt to overwrite job, failed (integer) 0 redis> GET job # Not overwritten "programmer"