Does Redis support expiration based on time to idle

1,174 views
Skip to first unread message

jdov...@gmail.com

unread,
Mar 3, 2017, 4:15:43 PM3/3/17
to Redis DB
I'm currently evaluating Redis as a distributed cache.

I've used Terracotta for many years and it does a good job except it doesn't permit horizontal scaling (sharding) unless you pay for a license.

Anyhow, one cool feature that Terracotta had was the ability to set time to idle (TTI) on a particular cache. It might even allow it on a key as well. 

What that means is that if a key has not been accessed in over n seconds, it get removed from the cache (along with the associated value). However, if the key is accessed before that n second limit, the timer gets reset to again. So long as the key is accessed frequently enough, it can stay alive much longer than n seconds or even indefinitely.

Time to idle is different than Time to Live which I believe Redis already supports.

Does Redis support Time to idle ?

AlexanderB

unread,
Mar 3, 2017, 6:15:40 PM3/3/17
to Redis DB
Redis won't support this out of the box, but it's very easy to do this in your app. 

What you'd do is just add a refresh to the ttl on every read. 

For instance replace a get, with a pipelined Expire + a Get. 

That way the expire time would be reset back to it's default value on every read. 

The one major downside is that this makes everything into a write operation and you'll need to be sure you're directing these reads to a master rather than trying to pull these reads off a replicated slave instance. 
Reply all
Reply to author
Forward
0 new messages