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)命令

Defensive Design for the Web

Defensive Design for the Web

37signals、Matthew Linderman、Jason Fried / New Riders / 2004-3-2 / GBP 18.99

Let's admit it: Things will go wrong online. No matter how carefully you design a site, no matter how much testing you do, customers still encounter problems. So how do you handle these inevitable bre......一起来看看 《Defensive Design for the Web》 这本书的介绍吧!

HTML 压缩/解压工具

HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具

JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器

在线进制转换器

各进制数互转换器