Posted on: 02/11/2018 in Programming. Last Updated on: 04/11/2018
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
If your application is successfully saving items in Redis, you should see something similar to this image:
The answer was right infront of my eyes, but I didn't know Redis well enough to know what i was looking for!
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"