Short:
In Redis Clusters, you are only allowed to use one Database.
What happens if you call the command php artisian cache:clear
?
Details:
Normally, when you are calling the command
php artisian cache:clear
your session and queue Redis database are not deleted, because of the use of different databases:
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
],
You can see that Redis uses the cache connection and cache connection of Redis has set the database to 1 by default.
Now if I want to migrate to Redis Clusters, this part is getting tricky. Because Redis Clusters only allows you to have one database.
According to this blog post my configuration has to look like this:
//the redis driver
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => 'redis',
],
//the `default` connection of the redis driver
//Note: The Laravel Redis facade is hard coded to use this connection unless its connection is explicitly specified
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => '0',
`prefix` => `d:`
],
//the `cache` connection of the redis driver
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => '0',
`prefix` => `c:`
],
//the `queue` connection of the redis driver
'queue' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => '0',
`prefix` => 'q:',
],
//the `session` connection of the redis driver
'session' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => '0',
#since config/session.php does not have an app level prefix we can change
#this prefx to `myapp:s:` if we share redis server between apps
`prefix` => `s:`
],
],
As you might see, the database
is set to 0. What happens when I call the command php artisian cache:clear
?
If you look at the official documentations https://laravel.com/docs/7.x/redis#configuration and scroll down to the part: Configuring Clusters
you see that database is also set to 0. However, one thing is unclear. It uses the array key clusters
.
So my question that arises with that: How do you cache:clear your application when you use Redis Clusters?