Redis Msetnx 命令

更新时间: 2019-07-07 15:54

Redis Msetnx 命令用于所有给定 key 都不存在时,同时设置一个或多个 key-value 对。

语法

redis 127.0.0.1:6379> MSETNX key1 value1 key2 value2 .. keyN valueN 

返回值

当所有 key 都成功设置,返回 1 。 如果所有给定 key 都设置失败(至少有一个 key 已经存在),那么返回 0 。

实例

实例1:所有 key 都不存在

127.0.0.1:6379> msetnx domain codercto domain1 codercto1 domain2 codercto2
1
127.0.0.1:6379> mget domain domain1 domain2
codercto
codercto1
codercto2

实例1:至少有一个 key 已经存在

127.0.0.1:6379> exists domain
1
127.0.0.1:6379> exists domain1
0
127.0.0.1:6379> exists domain2
0
127.0.0.1:6379> msetnx domain codercto domain1 codercto1 domain2 codercto2
0
127.0.0.1:6379> mget domain domain1 domain2
codercto


127.0.0.1:6379>

查看更多 Redis 字符串(String)命令

The Linux Command Line

The Linux Command Line

William E. Shotts Jr. / No Starch Press, Incorporated / 2012-1-17 / USD 39.95

You've experienced the shiny, point-and-click surface of your Linux computer-now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very ......一起来看看 《The Linux Command Line》 这本书的介绍吧!

HTML 压缩/解压工具

HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具

JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化

XML 在线格式化

在线 XML 格式化压缩工具