Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis store key without a value

Tags:

redis

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.

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?

like image 233
RienNeVaPlu͢s Avatar asked Aug 28 '14 20:08

RienNeVaPlu͢s


People also ask

Is Redis key-value store?

redis is an in-memory, key/value store. Think of it as a dictionary with any number of keys, each of which has a value that can be set or retrieved. However, Redis goes beyond a simple key/value store as it is actually a data structures server, supporting different kinds of values.

Can Redis store null?

Redis client to store a Null value in Redis? If you use IDatabase. StringGet(key) then the returning of Null is used to signify that there "was no result". Therefore if you use IDatabase.

Does Redis overwrite key?

Redis SET command is used to set some string value in redis key. If the key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on a successful SET operation. 1.0.

Can Redis only store strings?

As we have mentioned earlier that Redis is a key-value store, but that doesn't mean that it stores only string keys and string values. Redis supports different types of data structures as values. The key in Redis is a binary-safe String, with a max size of 512 MB, but you should always consider creating shorter keys.


1 Answers

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 
like image 81
Leonid Beschastny Avatar answered Oct 03 '22 01:10

Leonid Beschastny