Cached values not showing in Redis

So as the title mentions, I wasn't able to see any of my cached values in Redis. Normally everytime i've stashed a value in cache, i've been able to fetch it by its key or list all of the saved keys.

GET key

At first I wasn't sure that anything was actually being saved. There is a way to check this, you can issue the following command in your terminal

redis-cli monitor

If your application is successfully saving items in Redis, you should see something similar to this image:

Example output from redis-cli monitor command

The answer was right infront of my eyes, but I didn't know Redis well enough to know what i was looking for!

The Solution

Redis has 16 databases. Whenever i've used Redis, it just so happens that it used database 0 for everything. As 0 is the default database. Looking at the output from the monitor command, you can see the first command it issues is "SELECT" "1". This is Redis changing the database.

To prove this, you can issue another command from withing the Redis CLI:

# Keyspace

As you can see, db1 has 2 keys. You can change database by using the SELECT command followed by the database number. In my case this was SELECT 1.

Issue the KEYS * command once more and voilia, there are your cached values!

1) "cache:f1c4532dc98dd1b4bcdbe9f94d1e"
2) "cache:4dff7ca60b157dae0720a9ed321bd6"

More Posts