在Laravel中使用Cache Facade时未显示Redis密钥 [英] Redis keys not shown while using Cache facade in Laravel
问题描述
我正在使用Laravel Cache门面和 CACHE_DRIVER = redis
.所有数据都成功保存在Redis中,但是当我使用 redis-cli
并运行 keys *
时,没有键!
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!
在redis-cli 中使用命令 flushall时,它将再次从数据库中加载数据,这意味着密钥已经存储在Redis中.
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.
推荐答案
Redis有16个索引为0-15的数据库.默认数据库索引为 0
,因此,当您运行redis命令而不指定数据库时索引,您只对数据库索引 0
运行命令.但是,从Laravel 5.7开始,Laravel将所有缓存数据存储在数据库索引 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
.
为了查看缓存数据库中的键,您需要查询数据库 1
.您可以在命令行上使用 -n
开关指定数据库索引,也可以在redis提示符下使用 select
命令更改活动数据库.
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 "*"
或
#> redis-cli
127.0.0.1:6379> select 1
127.0.0.1:6379[1]> keys *
这篇关于在Laravel中使用Cache Facade时未显示Redis密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!