Reputation: 43
I'm trying to create two Predis\Client instances on the same PHP script to separate data belonging to different logical domains.
I do this as follows:
$param1 = [
'host' => 'localhost',
'port' => 6379,
'database' => 1,
];
$param2 = [
'host' => 'localhost',
'port' => 6379,
'database' => 3,
];
[... some code ...]
$redis1 = new Predis\Client($param1);
$redis2 = new Predis\Client($param2);
Here is the problem:
$redis1
correctly stores data into database 1 $redis2
stores data into database 0 instead of 3Do you have any idea why this happens?
Upvotes: 2
Views: 2425
Reputation: 43
I found the answer.
For some reason $param2
was erased to null
elsewhere in the code.
Predis\Client
doesn't fail but connect with default parameters!
Upvotes: 1
Reputation: 10015
Instantiate clients with new
:
$redis1 = new Predis\Client([
'host' => 'localhost',
'port' => 6379,
'database' => 1,
]);
$redis2 = new Predis\Client([
'host' => 'localhost',
'port' => 6379,
'database' => 3,
]);
Upvotes: 1