Key expiration
A simple and robust method to keep your Redis database from exceeding it's available memory is to set timeouts on keys that will be automatically evicted after the key's timeout expires. If your application does not need to retain stale or old data, having an effective expiration strategy for your key-space will keep the memory demands for your Redis application more manageable. A popular Redis design pattern using key expiration is to save expired or evicted data into another relational SQL database or other more disk-based NoSQL platform like MongoDB.
There are some aspects of key expiration that you should be aware of when implementing this feature in your application. First, when you call a timeout with the EXPIRE
command on a key, the timeout can only be cleared if you delete the key or replace the key. Any subsequent commands that alter the value do not change or clear out any timeouts you set. Let's create a scenario where you are programming an application...