Redis keys not shown while using Cache facade in Laravel

邮差的信 提交于 2021-02-16 05:28:07

问题


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.


回答1:


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 *



回答2:


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.)



来源:https://stackoverflow.com/questions/56566600/redis-keys-not-shown-while-using-cache-facade-in-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!