mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created RedisFactory which will create the redis adapter for the redis lock
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
"monolog/monolog": "^1.21",
|
"monolog/monolog": "^1.21",
|
||||||
"ocramius/proxy-manager": "^2.0",
|
"ocramius/proxy-manager": "^2.0",
|
||||||
"phly/phly-event-dispatcher": "^1.0",
|
"phly/phly-event-dispatcher": "^1.0",
|
||||||
|
"predis/predis": "^1.1",
|
||||||
"shlinkio/shlink-installer": "^1.2.1",
|
"shlinkio/shlink-installer": "^1.2.1",
|
||||||
"symfony/console": "^4.3",
|
"symfony/console": "^4.3",
|
||||||
"symfony/filesystem": "^4.3",
|
"symfony/filesystem": "^4.3",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Shlinkio\Shlink\Common\Cache\RedisFactory;
|
||||||
use Symfony\Component\Lock;
|
use Symfony\Component\Lock;
|
||||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||||
|
|
||||||
@@ -13,13 +14,20 @@ return [
|
|||||||
'dependencies' => [
|
'dependencies' => [
|
||||||
'factories' => [
|
'factories' => [
|
||||||
Lock\Store\FlockStore::class => ConfigAbstractFactory::class,
|
Lock\Store\FlockStore::class => ConfigAbstractFactory::class,
|
||||||
|
Lock\Store\RedisStore::class => ConfigAbstractFactory::class,
|
||||||
Lock\Factory::class => ConfigAbstractFactory::class,
|
Lock\Factory::class => ConfigAbstractFactory::class,
|
||||||
],
|
],
|
||||||
|
'aliases' => [
|
||||||
|
// With this config, a user could alias 'lock_store' => 'redis_lock_store' to override the default
|
||||||
|
'lock_store' => Lock\Store\FlockStore::class,
|
||||||
|
'redis_lock_store' => Lock\Store\RedisStore::class,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
ConfigAbstractFactory::class => [
|
ConfigAbstractFactory::class => [
|
||||||
Lock\Store\FlockStore::class => ['config.locks.locks_dir'],
|
Lock\Store\FlockStore::class => ['config.locks.locks_dir'],
|
||||||
Lock\Factory::class => [Lock\Store\FlockStore::class],
|
Lock\Store\RedisStore::class => [RedisFactory::SERVICE_NAME],
|
||||||
|
Lock\Factory::class => ['lock_store'],
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
13
config/autoload/redis.local.php.local
Normal file
13
config/autoload/redis.local.php.local
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'redis' => [
|
||||||
|
'servers' => 'tcp://shlink_redis:6379',
|
||||||
|
// 'servers' => [
|
||||||
|
// 'tcp://shlink_redis:6379',
|
||||||
|
// ],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
17
module/Common/config/cache.config.php
Normal file
17
module/Common/config/cache.config.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\Common;
|
||||||
|
|
||||||
|
use Doctrine\Common\Cache as DoctrineCache;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
DoctrineCache\Cache::class => Cache\CacheFactory::class,
|
||||||
|
Cache\RedisFactory::SERVICE_NAME => Cache\RedisFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Common;
|
namespace Shlinkio\Shlink\Common;
|
||||||
|
|
||||||
use Doctrine\Common\Cache as DoctrineCache;
|
|
||||||
use GeoIp2\Database\Reader;
|
use GeoIp2\Database\Reader;
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@@ -20,7 +19,6 @@ return [
|
|||||||
'dependencies' => [
|
'dependencies' => [
|
||||||
'factories' => [
|
'factories' => [
|
||||||
GuzzleClient::class => InvokableFactory::class,
|
GuzzleClient::class => InvokableFactory::class,
|
||||||
DoctrineCache\Cache::class => Cache\CacheFactory::class,
|
|
||||||
Filesystem::class => InvokableFactory::class,
|
Filesystem::class => InvokableFactory::class,
|
||||||
Reader::class => ConfigAbstractFactory::class,
|
Reader::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
|
|||||||
30
module/Common/src/Cache/RedisFactory.php
Normal file
30
module/Common/src/Cache/RedisFactory.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
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 is_string;
|
||||||
|
|
||||||
|
class RedisFactory
|
||||||
|
{
|
||||||
|
public const SERVICE_NAME = 'Shlinkio\Shlink\Common\Cache\Redis';
|
||||||
|
|
||||||
|
public function __invoke(ContainerInterface $container): PredisClient
|
||||||
|
{
|
||||||
|
$redisConfig = $container->get('config')['redis'] ?? [];
|
||||||
|
$servers = $redisConfig['servers'];
|
||||||
|
|
||||||
|
if (is_array($servers) && count($servers) === 1) {
|
||||||
|
$servers = array_shift($servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = is_string($servers) ? null : ['cluster' => 'redis'];
|
||||||
|
return new PredisClient($servers, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user