I'm writing a library that stores keys in Redis or Memcached. To keep it generic, I'd like to use SET
for all my set operations, but I'm struggling to find an expiry value that equates to "don't expire". Is there a sentinel value I can send?
For example, If there's an expiry of 100, I'd like to send:
SET myKey myValue ex 100 NX
but if there's no expiry, I'd prefer to do
SET myKey myValue ex -1 NX
rather than
SETNX myKey myValue
Interestingly, there doesn't appear to be any way to do the equivalent of a SET
using the XX
option without an expiry.
Just send the set command without an EX option.
Set key value NX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With