In the recipe Managing keys in Chapter 2, Data Types, we learned that Redis keys can be deleted by using the DEL or UNLINK command. Besides deleting keys manually, we can also ask Redis to delete keys automatically by setting the timeout on keys. In this recipe, we will illustrate how to set the timeout on Redis keys and explain the key expiration mechanism in Redis.
Setting expiration on keys
Getting ready…
You need to finish the installation of the Redis Server as we described in the Downloading and Installing Redis recipe in Chapter 1, Getting Started with Redis.