hexists 命令

hexists 命令用于查看哈希表的指定字段是否存在。

语法

HEXISTS KEY_NAME FIELD_NAME

返回值

如果哈希表含有给定字段,返回 1 。如果哈希表不含有给定字段,或 key 不存在,返回 0 。

实例

redis> HSET myhash field1 "foo"
(integer) 1

redis> HEXISTS myhash field1
(integer) 1

redis> HEXISTS myhash field2
(integer) 0