Faid
Faid

Reputation: 595

Redis keys not shown while using Cache facade in Laravel

I'm using Laravel Cache facade, and the CACHE_DRIVER=redis. All data is saved in Redis successfully, but when I use redis-cli and run keys* there are not keys!

When using the command flushall in redis-cli it loads the data again from the database, so that means the keys are already stored in Redis.

Upvotes: 8

Views: 2999

Answers (2)

shmuels
shmuels

Reputation: 1403

Update

This may have to do with Laravel cache prefixes in the redis block in the database.php config file. See here

See this answer for addtional details.

Previous Ans.

I had the same issue and I tried the accepted ans., however different databases was not the issue.

I was able to find the missing key using scan, like this Redis::scan('*'). Why using Redis::keys('*') is not returning the key, is still a mystery.

(To note only key:values created using Python were not returned with keys, those created with Laravel were.)

Upvotes: 3

patricus
patricus

Reputation: 62358

Redis has 16 databases indexed 0 - 15. The default database index is 0, so when you run redis commands without specifying the database index, you're only running commands against database index 0. However, as of Laravel 5.7, Laravel stores all the cache data in database index 1.

In order to see the keys in your cache database, you need to query database 1. You can either use the -n switch on the command line to specify the database index, or use the select command at the redis prompt to change the active database.

redis-cli -n 1 keys "*"

or

#> redis-cli
127.0.0.1:6379> select 1
127.0.0.1:6379[1]> keys *

Upvotes: 23

Related Questions