skip to Main Content

As you know Redis could have several databases, in my laravel setup ive defined 3 of them and using 2 at least

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

Thats what ive set in config/database.php

Furthermore, due to certain need I clear all cache using flushall() method:

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

However, it also clears the queue jobs which is not what I want. So is there a way to only flush database 0 and database 1 and not database 2?

2

Answers


  1. You may use select and flushdb commands together to flush only selected database.

    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.

    The following will select the database 1 first and flush only 1.

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

    It is going to execute following commands in redis;

    1596794331.068032 [0 127.0.0.1:55088] "SELECT" "1"
    1596794331.071332 [1 127.0.0.1:55088] "FLUSHDB"
    
    Login or Signup to reply.
  2. redis-cli -n [database number] flushdb

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search