Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis SET with option, without expiry

Tags:

redis

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.

like image 530
Ross McFarlane Avatar asked Dec 19 '22 12:12

Ross McFarlane


1 Answers

Just send the set command without an EX option.

Set key value NX 
like image 75
The Real Bill Avatar answered Jun 09 '23 05:06

The Real Bill