Can someone explain me how to store key/value pair in redis with unlimited exipire time?
I was trying to find some information at stackoverflow and google and I found nothing.
I’m using redisTemplate and I see there is only expire
method there with timeout to specify. I can eventually set the timeout to value like 999999999 days, but I think thats not the best solution.
2
Answers
Finally I found two answers to this question - at first I can use expire method with -1 value as a timeout:
and the second way is to use persist method on key:
This will remove the expiry time for the "mykey" key, effectively setting it to never expire.
By default, no expiry is set on the keys. That is, if you do not specify an expiry yourself, your key will be stored indefinetely without any expiry.
A return of
-1
tell us that there is no expiry set on the keymyname