如何通过哈希名检查哈希数据是否存在

How do I check hash data exists by hashname

如何通过哈希名检查哈希数据是否存在?

> hset test record1 data1
> hset test record2 data2
> hset test record3 data3
> hgetall test

127.0.0.1:6379> hgetall test
1) "record1"
2) "data1"
3) "record2"
4) "data2"
5) "record3"
6) "data3"

127.0.0.1:6379> hexists test
(error) ERR wrong number of arguments for 'hexists' command

提前致谢

您可以使用 HLEN,如果 returns 为零,则它们的哈希值不存在。

redis> HLEN test
(integer) 3
redis> HLEN non_existent_hash_key
(integer) 0

试试这个命令,它会解决你的问题。

redis> EXISTS test
(integer) 1