开发者

How do I keep the expiration of a Redis Key, even when I set something to it?

SET a 100 EXPIRE a 86400

OK, right now, "a" will expire within a day. I want SET "a" to other values, but I still want it to expire based on the initial "EXPIRE" that I created.

In other words, don't remove the EXPIRE when开发者_如何学编程 I set "a" to something new.


This is something I requested 2 years ago and now it was added (https://github.com/antirez/redis/pull/6679).

SET foo 1 KEEPTTL

This will get in with some next release.


If you're doing this from the command line, you can't do it precisely. The best you could do is to manually set the new key's expire time as a's remaining TTL (TTL a).

If you're communicating with Redis from a program you could probably fetch a's expire time and set that value as the new key's expire time fast enough to be precise.


try setex bcz its faster & atomic

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜