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 MSETNX command syntax

Function:Set one or more key-value pairs at the same time, if and only if all given keys do not exist. MSETNX will refuse to perform all set operations for a given key, even if only one of the given key already exists.

Syntax: MSETNX key value [key value ...]

Description: MSETNX is atomic, so it can be used as a setting Multiple different keys represent unique logic objects of different fields. All fields are either all set or none are set.

Available versions: >= 1.0.1

Time complexity: O(N), N is the number of keys to be set .

Return: When all keys are successfully set, return 1. If all given keys fail to be set (at least one key already exists), then 0 is returned.

redis MSETNX command example

# 对不存在的 key 进行 MSETNX
redis> MSETNX rmdbs "MySQL" nosql "MongoDB" key-value-store "redis"
(integer) 1
redis> MGET rmdbs nosql key-value-store
1) "MySQL"
2) "MongoDB"
3) "redis"
# MSET 的给定 key 当中有已存在的 key
redis> MSETNX rmdbs "Sqlite" language "python"  # rmdbs 键已经存在,操作失败
(integer) 0
redis> EXISTS language                          # 因为 MSET 是原子性操作,language 没有被设置
(integer) 0
redis> GET rmdbs                                # rmdbs 也没有被修改
"MySQL"