Laravel Redis / 如何只刷新特定的 redis 数据库?

Laravel Redis / How to you flush only a specific redis database?

如您所知,Redis 可能有多个数据库,在我的 laravel 设置中我定义了其中的 3 个并且至少使用了 2 个

'0' (default)
'1' (cache)
'2' (queue)

这就是我在 config/database 中设置的内容。php

此外,由于某些需要,我使用flushall()方法清除了所有缓存:

@Cache::flush();
@Redis::flushall();

但是,它也清除了队列作业,这不是我想要的。那么有没有办法只刷新数据库 0 和数据库 1 而不是数据库 2?

您可以同时使用 select and flushdb 命令来仅刷新 selected 数据库。

Select the Redis logical database having the specified zero-based numeric index. New connections always use the database 0.

Delete all the keys of the currently selected DB.

以下将 select 数据库 1 首先刷新 1

Redis::select(1);
Redis::flushdb();

它将在redis中执行以下命令;

1596794331.068032 [0 127.0.0.1:55088] "SELECT" "1"
1596794331.071332 [1 127.0.0.1:55088] "FLUSHDB"