Skip to content

Commit e81e97a

Browse files
authored
Added option redundant_servers (#48)
1 parent 775dabc commit e81e97a

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/Factory/MemcacheFactory.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ public function getAdapter(array $config)
3232
$client = new Memcache();
3333
$client->connect($config['host'], $config['port']);
3434

35+
foreach ($config['redundant_servers'] as $server) {
36+
if (!isset($server['host'])) {
37+
continue;
38+
}
39+
$port = $config['port'];
40+
if (isset($server['port'])) {
41+
$port = $server['port'];
42+
}
43+
$client->addserver($server['host'], $port);
44+
}
45+
3546
return new MemcacheCachePool($client);
3647
}
3748

@@ -41,11 +52,13 @@ public function getAdapter(array $config)
4152
protected static function configureOptionResolver(OptionsResolver $resolver)
4253
{
4354
$resolver->setDefaults([
44-
'host' => '127.0.0.1',
45-
'port' => 11211,
55+
'host' => '127.0.0.1',
56+
'port' => 11211,
57+
'redundant_servers' => [],
4658
]);
4759

4860
$resolver->setAllowedTypes('host', ['string']);
4961
$resolver->setAllowedTypes('port', ['string', 'int']);
62+
$resolver->setAllowedTypes('redundant_servers', ['array']);
5063
}
5164
}

src/Factory/MemcachedFactory.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public function getAdapter(array $config)
3333
$client = new Memcached($config['persistent_id']);
3434
$client->addServer($config['host'], $config['port']);
3535

36+
foreach ($config['redundant_servers'] as $server) {
37+
if (!isset($server['host'])) {
38+
continue;
39+
}
40+
$port = $config['port'];
41+
if (isset($server['port'])) {
42+
$port = $server['port'];
43+
}
44+
$client->addServer($server['host'], $port);
45+
}
46+
3647
$pool = new MemcachedCachePool($client);
3748

3849
if (null !== $config['pool_namespace']) {
@@ -48,15 +59,17 @@ public function getAdapter(array $config)
4859
protected static function configureOptionResolver(OptionsResolver $resolver)
4960
{
5061
$resolver->setDefaults([
51-
'persistent_id' => null,
52-
'host' => '127.0.0.1',
53-
'port' => 11211,
54-
'pool_namespace' => null,
62+
'persistent_id' => null,
63+
'host' => '127.0.0.1',
64+
'port' => 11211,
65+
'pool_namespace' => null,
66+
'redundant_servers' => [],
5567
]);
5668

5769
$resolver->setAllowedTypes('persistent_id', ['string', 'null']);
5870
$resolver->setAllowedTypes('host', ['string']);
5971
$resolver->setAllowedTypes('port', ['string', 'int']);
6072
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
73+
$resolver->setAllowedTypes('redundant_servers', ['array']);
6174
}
6275
}

0 commit comments

Comments
 (0)