Redis store key without a value

RienNeVaPlu͢s picture RienNeVaPlu͢s · Aug 28, 2014 · Viewed 18.6k times · Source

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.

However, Redis requires any key to have a value.

What would be the most reasonable value to use - if you don't ever want to read it?

Answer

Leonid Beschastny picture Leonid Beschastny · Sep 4, 2014

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