3

Does Redis support sliding expiration natively? If not, what is the best workaround?

Thanks, Pavan.

Tech Solver
  • 513
  • 1
  • 5
  • 16
  • 1
    What exactly does "sliding expiration" mean? – Not_a_Golfer Feb 21 '16 at 11:37
  • I would use a Lua script, so everytime you want to access a key you would get it with Lua and you can set also the expiration time. Of course if the key is gone, you don't return anything. – Liviu Costea Feb 21 '16 at 16:23

2 Answers2

0

If "Sliding Expiration" means "Key Eviction" then you have an answer here.

Community
  • 1
  • 1
Cosmin Ioniță
  • 3,598
  • 4
  • 23
  • 48
  • 6
    The linked answer is not what OP is asking about. Sliding Expiration means when a key gets a hit its expiration countdown is reset by the absolute expiration time specified when the key was created in the cache. Hence why it's called "sliding" expiration. What you've linked is what Redis does when it is out of memory and how it makes more room to accept new keys, i.e., if you want it to make more room. You could have it reject the writes by using the "noeviction" policy on maxmemory, which is the default behavior. – praneetloke Jul 21 '16 at 21:56
0

The work around will be to use Redisson Library which will allow you to set maxIdleTimeout. This will slide the Expiration. For more reference https://redisson.org/glossary/spring-cache.html

zelshu
  • 1
  • 2