Redis Hsetnx 命令

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

Redis Hsetnx 命令用于为哈希表中不存在的的字段赋值 。

如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作。

如果字段已经存在于哈希表中,操作无效。

如果 key 不存在,一个新哈希表被创建并执行 HSETNX 命令。

语法

redis 127.0.0.1:6379> HSETNX KEY_NAME FIELD VALUE

返回值

设置成功,返回 1 。 如果给定字段已经存在且没有操作被执行,返回 0 。

实例

redis 127.0.0.1:6379> HSETNX myhash field1 "foo"
(integer) 1
redis 127.0.0.1:6379> HSETNX myhash field1 "bar"
(integer) 0
redis 127.0.0.1:6379> HGET myhash field1
"foo"

redis 127.0.0.1:6379> HSETNX nosql key-value-store redis
(integer) 1

redis 127.0.0.1:6379> HSETNX nosql key-value-store redis       # 操作无效, key-value-store 已存在
(integer) 0

查看更多 Redis 哈希(Hash)命令

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 编码/解码

RGB CMYK 转换工具

RGB CMYK 转换工具

RGB CMYK 互转工具