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
KEYS *

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:

redis-cli
INFO KEYSPACE
# Keyspace
db1:keys=2,expires=2,avg_ttl=189046333

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!

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


More Posts

Amazon Kids Plus Review

My Daughter has been using Amazon Kids+ For over a year. Is it worth it, is it any good? A...

Notifications delayed on Android Pie?

Just recently I noticed that notifications for WhatsApp and Facebook Messenger were not coming through. They'd only show if I...

Laravel Queue Delays Not Working

Using Laravel 5.7 queues along with Redis I found that whilst the events were being dispatched and handled by the...