Search code examples
javaredisspring-session

Is Redis capable of using hard disk when it runs out of memory?


Redis is the default implementation for Java's Spring session storage. But Redis is an in-memory value-key storage and sooner or later it will run out of memory. And once it does, it will do one of the following:

  • Throws an error for commands requesting new memory
  • Frees memory according to policy set in the configuration (maxmemory-policy).

I see that there has been some feature called Virtual Memory in Redis but it's been discontinued and since version 2.4, it's not available.

Is Redis capable of using hard disk as the backup storage when it runs out of memory or it's really a bad choice for session storage? Or maybe Redis relies on OS to use swap as the last resort?

I'm using Redis 3 and Spring session 1.1.1


Solution

  • Yes and no.

    Redis won't fall over when you exceed RAM but it's really not recommended.

    An interesting related article by the Redis author: http://antirez.com/news/52

    That doesn't mean that Redis is a bad choice for session storage, it just means that you need to plan/size your architecture/RAM appropriately based on your capacity requirements.