The idea is:
Support more of the Redis SET options, in particular the GET
and NX
options to allow using the Redis node for atomic caching applications.
- The
GET
option causes the SET operation to return the value of the given key if it already exists. - The
NX
option causes the key to be set only if it does not already exist. If it does already exist, it returns nil.
Combining these two options allows a single (atomic) operation to either retrieve a cached value, or set it.
Without the ability to perform this task atomically, race conditions occur and performing tasks like deduplication on data that arrives at the same time and/or at a very high rate becomes unreliable.
This is outlined in a few other posts on the community forum, but I believe this is the best post about it: How do you handle getting only new items/deduplicating your APIs/services?
While the GET
and NX
options are the ones that I would like/need for my current use case, supporting all of the options would be ideal (and I’m sure there’s many in operations other than SET which would be appreciated too). Here’s the complete list of available options for SET, from the Redis documentation (linked below):
Options
The SET
command supports a set of options that modify its behavior:
EX
seconds – Set the specified expire time, in seconds (a positive integer).PX
milliseconds – Set the specified expire time, in milliseconds (a positive integer).EXAT
timestamp-seconds – Set the specified Unix time at which the key will expire, in seconds (a positive integer).PXAT
timestamp-milliseconds – Set the specified Unix time at which the key will expire, in milliseconds (a positive integer).NX
– Only set the key if it does not already exist.XX
– Only set the key if it already exists.KEEPTTL
– Retain the time to live associated with the key.GET
– Return the old string stored at key, or nil if key did not exist. An error is returned andSET
aborted if the value stored at key is not a string.
My use case:
- Use redis as a cache for reliable deduplication of incoming messages/data, in particular high message rates in a short/same period of frame.
I think it would be beneficial to add this because:
- These are some of the basic options Redis supports and are important to use it to its fullest.
Any resources to support this?
Are you willing to work on this?
- Possibly, I’ll be looking at the code and see what I can do.