Cached values not showing in Redis

Posted on: 02/11/2018. Last updated at: 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

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"



Picture of Daniel Ord
Daniel Ord

Building things for the Web. Follow me on Twitter or checkout my GitHub.

More Posts

Perfect PageSpeed score using Bootstrap and mod_pagespeed
I've never really gave the PageSpeed score of the websites that i've built too much consideration, as long as they...
How to set file permissions for Laravel 5 on mac OSX
Every time I do a fresh install of Laravel I always run into the same error where laravel.log couldn't be...
How to create a simple sitemap for Wink
If you're using Wink for your blog, here's how to setup up a simple sitemap to list your posts and...
How to Install Laravel Spark
Doing a fresh install of Laravel Spark or even an upgrade has proved problematic almost every time i attempt it....

Other Categories