diff --git a/composer.json b/composer.json index 533add72..a896040d 100644 --- a/composer.json +++ b/composer.json @@ -41,14 +41,13 @@ "ocramius/proxy-manager": "^2.11", "pagerfanta/core": "^3.5", "php-middleware/request-id": "^4.1", - "predis/predis": "^1.1", "pugx/shortid-php": "^1.0", "ramsey/uuid": "^4.2", - "shlinkio/shlink-common": "dev-main#0396706 as 4.5", + "shlinkio/shlink-common": "dev-main#4019020 as 4.5", "shlinkio/shlink-config": "^1.6", "shlinkio/shlink-event-dispatcher": "^2.4", "shlinkio/shlink-importer": "^3.0", - "shlinkio/shlink-installer": "^7.1", + "shlinkio/shlink-installer": "dev-develop#f76e9aa as 7.2", "shlinkio/shlink-ip-geolocation": "^2.2", "symfony/console": "^6.0", "symfony/filesystem": "^6.0", diff --git a/config/autoload/installer.global.php b/config/autoload/installer.global.php index 3cada5db..c82b4a97 100644 --- a/config/autoload/installer.global.php +++ b/config/autoload/installer.global.php @@ -32,6 +32,7 @@ return [ Option\Worker\WebWorkerNumConfigOption::class, Option\Redis\RedisServersConfigOption::class, Option\Redis\RedisSentinelServiceConfigOption::class, + Option\Redis\RedisPubSubConfigOption::class, Option\UrlShortener\ShortCodeLengthOption::class, Option\Mercure\EnableMercureConfigOption::class, Option\Mercure\MercurePublicUrlConfigOption::class, diff --git a/config/autoload/locks.global.php b/config/autoload/locks.global.php index 9b014496..5e37e770 100644 --- a/config/autoload/locks.global.php +++ b/config/autoload/locks.global.php @@ -3,7 +3,7 @@ declare(strict_types=1); use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; -use Predis\ClientInterface as PredisClient; +use Shlinkio\Shlink\Common\Cache\RedisFactory; use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory; use Shlinkio\Shlink\Core\Config\EnvVars; use Symfony\Component\Lock; @@ -38,7 +38,7 @@ return [ ConfigAbstractFactory::class => [ Lock\Store\FlockStore::class => ['config.locks.locks_dir'], - Lock\Store\RedisStore::class => [PredisClient::class], + Lock\Store\RedisStore::class => [RedisFactory::SERVICE_NAME], Lock\LockFactory::class => ['lock_store'], LOCAL_LOCK_FACTORY => ['local_lock_store'], ], diff --git a/config/autoload/redis.global.php b/config/autoload/redis.global.php index 0133d1b1..a01d0279 100644 --- a/config/autoload/redis.global.php +++ b/config/autoload/redis.global.php @@ -14,6 +14,7 @@ return (static function (): array { 'redis' => [ 'servers' => $redisServers, 'sentinel_service' => EnvVars::REDIS_SENTINEL_SERVICE->loadFromEnv(), + 'pub_sub_enabled' => (bool) EnvVars::REDIS_PUB_SUB_ENABLED->loadFromEnv(false), ], ], ], diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 96907a5d..7ca2e072 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -24,12 +24,14 @@ return [ EventDispatcher\Event\VisitLocated::class => [ EventDispatcher\Mercure\NotifyVisitToMercure::class, EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class, + EventDispatcher\RedisPubSub\NotifyVisitToRedis::class, EventDispatcher\NotifyVisitToWebHooks::class, EventDispatcher\UpdateGeoLiteDb::class, ], EventDispatcher\Event\ShortUrlCreated::class => [ EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class, EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class, + EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class, ], ], ], @@ -42,6 +44,8 @@ return [ EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => ConfigAbstractFactory::class, EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => ConfigAbstractFactory::class, EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => ConfigAbstractFactory::class, + EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => ConfigAbstractFactory::class, + EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => ConfigAbstractFactory::class, EventDispatcher\UpdateGeoLiteDb::class => ConfigAbstractFactory::class, ], @@ -58,6 +62,12 @@ return [ EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => [ EventDispatcher\CloseDbConnectionEventListenerDelegator::class, ], + EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => [ + EventDispatcher\CloseDbConnectionEventListenerDelegator::class, + ], + EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => [ + EventDispatcher\CloseDbConnectionEventListenerDelegator::class, + ], EventDispatcher\NotifyVisitToWebHooks::class => [ EventDispatcher\CloseDbConnectionEventListenerDelegator::class, ], @@ -107,6 +117,8 @@ return [ ShortUrl\Transformer\ShortUrlDataTransformer::class, Options\RabbitMqOptions::class, ], + EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => [], + EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => [], EventDispatcher\UpdateGeoLiteDb::class => [GeolocationDbUpdater::class, 'Logger_Shlink'], ], diff --git a/module/Core/src/Config/EnvVars.php b/module/Core/src/Config/EnvVars.php index 33abae01..a68f24f3 100644 --- a/module/Core/src/Config/EnvVars.php +++ b/module/Core/src/Config/EnvVars.php @@ -19,6 +19,7 @@ enum EnvVars: string case GEOLITE_LICENSE_KEY = 'GEOLITE_LICENSE_KEY'; case REDIS_SERVERS = 'REDIS_SERVERS'; case REDIS_SENTINEL_SERVICE = 'REDIS_SENTINEL_SERVICE'; + case REDIS_PUB_SUB_ENABLED = 'REDIS_PUB_SUB_ENABLED'; case MERCURE_PUBLIC_HUB_URL = 'MERCURE_PUBLIC_HUB_URL'; case MERCURE_INTERNAL_HUB_URL = 'MERCURE_INTERNAL_HUB_URL'; case MERCURE_JWT_SECRET = 'MERCURE_JWT_SECRET'; diff --git a/module/Core/src/EventDispatcher/Mercure/NotifyVisitToMercure.php b/module/Core/src/EventDispatcher/Mercure/NotifyVisitToMercure.php index 11d3a8e4..f9610021 100644 --- a/module/Core/src/EventDispatcher/Mercure/NotifyVisitToMercure.php +++ b/module/Core/src/EventDispatcher/Mercure/NotifyVisitToMercure.php @@ -25,9 +25,9 @@ class NotifyVisitToMercure ) { } - public function __invoke(VisitLocated $shortUrlLocated): void + public function __invoke(VisitLocated $visitLocated): void { - $visitId = $shortUrlLocated->visitId; + $visitId = $visitLocated->visitId; /** @var Visit|null $visit */ $visit = $this->em->find(Visit::class, $visitId); diff --git a/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php b/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php index 34a951ec..1208c291 100644 --- a/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php +++ b/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php @@ -26,13 +26,13 @@ class NotifyVisitToRabbitMq ) { } - public function __invoke(VisitLocated $shortUrlLocated): void + public function __invoke(VisitLocated $visitLocated): void { if (! $this->options->isEnabled()) { return; } - $visitId = $shortUrlLocated->visitId; + $visitId = $visitLocated->visitId; $visit = $this->em->find(Visit::class, $visitId); if ($visit === null) { diff --git a/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php b/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php new file mode 100644 index 00000000..6813fba3 --- /dev/null +++ b/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php @@ -0,0 +1,15 @@ +