Redis存储没有值的键 [英] Redis store key without a value
本文介绍了Redis存储没有值的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Redis expire 命令时,例如 SETEX代码>
和TTL
,在某些情况下,密钥根本不需要保存值,因为生存时间就是如此.
When using the Redis expire commands like SETEX
and TTL
, there are scenarios in which there is no need for the key to hold a value at all, because the time to live acts as such.
但是,Redis 要求任何键都具有值.
如果您不想阅读,最合理的值是什么?
What would be the most reasonable value to use - if you don't ever want to read it?
推荐答案
谁说你真的应该在 redis key 中存储任何东西?
Who said that you should actually store anything in redis key?
空字符串 ""
是一个完全有效的 redis 键值,而且是最短的:
Empty string ""
is a perfectly valid value for a redis key, and it's a shortest possible one:
> SET foo ""
OK
> GET foo
""
> BITCOUNT foo
(integer) 0
这篇关于Redis存储没有值的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文