问题
note: this is a follow up to this question
I need to be able to do both redis clustering and replication. This is the config file I have in laravel:
'redis' => [
'clustered' => [
'client' => 'predis',
'cluster' => true,
'options' => [ 'cluster' => 'redis',
'replication' => true
],
'clusters' => [
// masters
[
'host' => env('REDIS_SHARD_1_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_1_PORT', 6379),
'database' => 0,
'alias' => 'master',
],
[
'host' => env('REDIS_SHARD_2_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_2_PORT', 6379),
'database' => 0,
'alias' => 'master',
],
[
'host' => env('REDIS_SHARD_3_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_3_PORT', 6379),
'database' => 0,
'alias' => 'master',
],
// slaves (replicas)
[
'host' => env('REDIS_SHARD_1_HOST_REPLICA', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_1_PORT_REPLICA', 6379),
'database' => 0,
],
[
'host' => env('REDIS_SHARD_2_HOST_REPLICA', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_2_PORT_REPLICA', 6379),
'database' => 0,
],
[
'host' => env('REDIS_SHARD_3_HOST_REPLICA', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_SHARD_3_PORT_REPLICA', 6379),
'database' => 0,
]
],
],
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => 6379,
'database' => 0,
'cluster' => false,
],
]
];
but in my debugger, the connection that gets created in predis has 3 slaves and the last master:
[ *Locals ] [ Superglobals ] [ User defined constants ]
- Locals at /Users/Shared/dev/php/toters-api/vendor/predis/predis/src/Client.php:138
▾ $connection = (Predis\Connection\Aggregate\MasterSlaveReplication [6])
\
▸ $connection->strategy = (Predis\Replication\ReplicationStrategy [3])
|
▾ $connection->master = (Predis\Connection\StreamConnection [4])
\
⬦ $connection->master->*Predis\Connection\AbstractConnection*resource = (null)
|
⬦ $connection->master->*Predis\Connection\AbstractConnection*cachedId = (null)
|
▸ $connection->master->parameters = (Predis\Connection\Parameters [2])
|
▸ $connection->master->initCommands = (array [1])
/
▾ $connection->slaves = (array [3])
\
▸ $connection->slaves['slave-localhost:7003'] = (Predis\Connection\StreamConnection [4])
|
▸ $connection->slaves['slave-localhost:7004'] = (Predis\Connection\StreamConnection [4])
|
▸ $connection->slaves['slave-localhost:7005'] = (Predis\Connection\StreamConnection [4])
/
⬦ $connection->current = (null)
|
⬦ $connection->autoDiscovery = (bool) 0
|
⬦ $connection->connectionFactory = (null)
/
⬦ $initializer = (uninitialized)
|
▾ $options = (Predis\Configuration\Options [3])
\
▸ $options->input = (array [1])
|
▸ $options->options = (array [2])
|
▸ $options->handlers = (array [6])
/
▾ $parameters = (array [6])
\
▸ $parameters[0] = (array [5])
|
▸ $parameters[1] = (array [5])
|
▸ $parameters[2] = (array [5])
|
▸ $parameters[3] = (array [4])
|
▸ $parameters[4] = (array [4])
|
▸ $parameters[5] = (array [4])
/
▾ $replication = (Predis\Connection\Aggregate\MasterSlaveReplication [6])
\
▸ $replication->strategy = (Predis\Replication\ReplicationStrategy [3])
|
▾ $replication->master = (Predis\Connection\StreamConnection [4])
\
⬦ $replication->master->*Predis\Connection\AbstractConnection*resource = (null)
|
⬦ $replication->master->*Predis\Connection\AbstractConnection*cachedId = (null)
|
▸ $replication->master->parameters = (Predis\Connection\Parameters [2])
|
▸ $replication->master->initCommands = (array [1])
/
▾ $replication->slaves = (array [3])
\
▸ $replication->slaves['slave-localhost:7003'] = (Predis\Connection\StreamConnection [4])
|
▸ $replication->slaves['slave-localhost:7004'] = (Predis\Connection\StreamConnection [4])
|
▸ $replication->slaves['slave-localhost:7005'] = (Predis\Connection\StreamConnection [4])
/
⬦ $replication->current = (null)
|
⬦ $replication->autoDiscovery = (bool) 0
|
⬦ $replication->connectionFactory = (null)
/
▾ $this = (Predis\Client [3])
\
⬦ $this->connection = (null)
|
▸ $this->options = (Predis\Configuration\Options [3])
|
⬦ $this->profile = (null)
/
how can i write the config to have three nodes in a cluster, with each node having one replica?
来源:https://stackoverflow.com/questions/57761328/how-to-create-a-predis-client-that-does-both-clustering-and-replication