Redis store key without a value

浪子不回头ぞ 提交于 2019-12-03 05:23:24

Who said that you should actually store anything in redis key?

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

I would store one byte of data that could also be broadly interpreted as "truthy", such as the ASCII character 1.

Do you serialize everything coming to and from redis, yourself? If so, you may consider using a sentinel value (like a NONE constant, etc.) which is set to something like 'None'.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!