redis SETNX command


  Translation results:

set

英[set] 美[sɛt]

vt. Set; place, arrange; put in a certain situation; place tableware

vi. Setting off; setting off; condensation

n.Gathering; a set; a set; a TV set

adj. Fixed; located in...; stubborn; arranged The

third person singular: sets plural: sets present participle: setting past tense: set past participle: set

redis SETNX commandsyntax

Function: Set the value of key to value if and only if key does not exist. If the given key already exists, SETNX takes no action.

Syntax: SETNX key value

Explanation: SETNX is the abbreviation of "SET if Not eXists" (if it does not exist, then SET).

Available versions: >= 1.0.0

Time complexity: O(1)

Return: Set successfully, return 1. Setup fails and returns 0.

redis SETNX commandexample

redis> EXISTS job                # job 不存在
(integer) 0
redis> SETNX job "programmer"    # job 设置成功
(integer) 1
redis> SETNX job "code-farmer"   # 尝试覆盖 job ,失败
(integer) 0
redis> GET job                   # 没有被覆盖
"programmer"

Home

Videos

Q&A