mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Added support in RedisFactory to provide servers as a comma-separated string
This commit is contained in:
parent
b0bb77ca81
commit
04389fc8b0
2 changed files with 7 additions and 7 deletions
|
@ -6,9 +6,8 @@ namespace Shlinkio\Shlink\Common\Cache;
|
|||
use Predis\Client as PredisClient;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use function array_shift;
|
||||
use function count;
|
||||
use function is_array;
|
||||
use function explode;
|
||||
use function is_string;
|
||||
|
||||
class RedisFactory
|
||||
|
@ -18,13 +17,11 @@ class RedisFactory
|
|||
public function __invoke(ContainerInterface $container): PredisClient
|
||||
{
|
||||
$redisConfig = $container->get('config')['redis'] ?? [];
|
||||
|
||||
$servers = $redisConfig['servers'] ?? [];
|
||||
$servers = is_string($servers) ? explode(',', $servers) : $servers;
|
||||
$options = count($servers) <= 1 ? null : ['cluster' => 'redis'];
|
||||
|
||||
if (is_array($servers) && count($servers) === 1) {
|
||||
$servers = array_shift($servers);
|
||||
}
|
||||
|
||||
$options = is_string($servers) || count($servers) < 1 ? null : ['cluster' => 'redis'];
|
||||
return new PredisClient($servers, $options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,5 +54,8 @@ class RedisFactoryTest extends TestCase
|
|||
yield 'empty cluster of servers' => [[
|
||||
'servers' => [],
|
||||
], PredisCluster::class];
|
||||
yield 'cluster of servers as string' => [[
|
||||
'servers' => 'tcp://1.1.1.1:6379,tcp://2.2.2.2:6379',
|
||||
], RedisCluster::class];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue