I am trying to cache my results using redis
in Laravel
by doing this
$result = Cache::remember('orders_cache', 10, function () use ($orders) {
return $orders;
});
return $result;
When I go in my Redis-Cli and do KEYS *
, I don’t see orders_cache
key there. I have set the cache_driver
to redis
in my .env
and I also ran the command php artisan config:cache
. I have also installed predis package using composer as well.
My Dev environment is:
- PHP7.4
- Ubuntu 20
- Laravel 6.0
- Redis 5.0.7
Any help on this would be appreciated.
TIA
4
Answers
run
redis-cli monitor
and check the database number and written key.In recent versions of Laravel (8.^), it prepends the laravel_database with Redis keys.
E.g: laravel_database_{$YOUR_KEY}.
In order to see what keys are available RUN:
KEYS *
Redis instance supports 16 logical databases and numbered from 0 to 15, by default by runnig
redis-cli
you connect to database0
. you can take advantage of the Redis INFO command to show databases that contain keys and also another more info like:That in may case, I have 2 database. now you can change the database you’re using with the
select
command after you connect. for example:and it will return
OK
if the switch is successful. now you can see your laravel keys.I ran into a similar issue in where my key saved via Laravel was being returned, when queried via Laravel, using
Redis::keys('*')
, however a key saved via Python was not. I’m still not sure why (and separate databases as noted here was not the cause).Interestingly, I was able to see the key, saved via Python, using
Redis::scan('*')
(docs). Even thoughscan
returned the key, I am still not able to get it viaRedis::get('key_name')
. I need to do further research as to why this is the case, but this may be useful in finding your missing key.