Reputation: 49
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', 'secret'),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'session' => [
'host' => env('REDIS_HOST', 'redis'),
'password' => env('REDIS_PASSWORD', 'secret'),
'port' => env('REDIS_PORT', 6379),
'database' => 1,
],
Can anyone explain the database parameter in config/database.php file , I am clueless regarding this parameter as it is not stated in the docs .
According to another website , to set up session to use the redis driver , need to add another redis database and this parameter is set to 1 but it points to the same redis instance. I'm quite confused .
Thank you
Based on more digging through redis docs I've come to a conclusion . Please do correct me if i'm wrong .
The database parameter indicates that to place in which redis database . According to the docs , Redis has by default 16 databases.
CONFIG GET databases
1) "databases"
2) "16"
And by placing the parameter database , we are indicating which database to use , for example place all the session keys to database 1 instead of database 0 which we can access by using the
SELECT db_number E.g SELECT 1
Please let me know if my conclusion is correct or wrong . Thank you =)
Upvotes: 4
Views: 7421
Reputation: 1424
A redis instance has multiple databases as you stated. The database parameter tells redis which database to use inside the instance. The instance is defined in "host".
You don't need to select database in code level with "select" since you have declared the database in config.
If you omit the "database" param, then the default "0" database will be used.
If you want to use multiple databases (e.g cache to one db, sessions to another) then you need to create multiple connections in your config.
Upvotes: 2