expire 44, 10
After 20 seconds
ttl 44
Result is:
-1, or sometimes, -2
Why could this be? Using ElastiCache Redis version 3.2.4
Comment From: antirez
Hello, -1 means the key has no expire set, probably another client set the key again without expire. -2 means instead that the key has been deleted. I'm not sure from your description what is wrong.
Comment From: heroic
@antirez Getting a -1 is what is wrong. As you can see in the sequence above. I did explicitly set a expire on a key, and I can confirm the key existed. After the expiry seconds have elapsed, I am expecting ttl to give -2 as you said, but I am getting -1 at times. It is not happening every time though, and hence I don't have a exact way of replicating this issue.
Comment From: badboy
Run redis-cli MONITOR in another shell. Someone/Something is explicitely setting that key again.
Comment From: deverhjj
@badboy Yes, you are right !!!, I encountered this problem.
Comment From: juliocde
@badboy Yes, you are right !!!, I encountered this problem.
How to solve the problem? Interestingly, sometimes a record with a value of -1 appears and never expires.
Comment From: vishalraj82
I am also having similar problem. Despite setting expiration for key, sometimes the key persists beyond the specified TTL and needs to be purged manually. I am using version 4.0.9.
Comment From: fz-29
@heroic You have closed the issue, so did you find the solution to this problem or was something wrong with the expectation? Please let us know here, I'm also facing similar issue.
Comment From: heroic
@fz-29 Another process was setting the key to a value without expire.
Comment From: tmacjx
if you expire an key on salve redis, it will not expire anyway.Only when you expire on master redis.It's will del normally!
https://github.com/redis/redis/issues/187