Ross McFarlane
Ross McFarlane

Reputation: 4254

Redis SET with option, without expiry

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.

Upvotes: 7

Views: 20925

Answers (1)

The Real Bill
The Real Bill

Reputation: 15793

Just send the set command without an EX option.

Set key value NX 

Upvotes: 15

Related Questions