Reputation: 53
Using Redis as cache service to cache some non-important data, and there is a case that need to update the value without reset or override the expire time, is there any good way to resolve this problem? I've searched and found follows 2 solutions
Any good idea to resolve this problem?
Upvotes: 5
Views: 7309
Reputation: 181280
You don't need to do any of those two things. You just need to use the KEEPTTL
flag when you set your value.
Like this:
> set my_key this_is_my_value EX 60
This will set a value for a key with 60 seconds expiration.
Then, when you change the value and don't want to change the expiration of your key, just do:
> set my_key this_is_my_new_value KEEPTTL
More information on REDIS docs.
Upvotes: 8