From 074f2135f61367b43d0df8fc6abf37a929bd2558 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandrocelaya@gmail.com>
Date: Tue, 12 Sep 2023 21:20:38 +0200
Subject: [PATCH] Make sure locks include the same cache namespace when sent to
 Redis

---
 CHANGELOG.md                     | 1 +
 composer.json                    | 2 +-
 config/autoload/locks.global.php | 6 +++++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6539166a..bb9f5f0c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
 
 ### Fixed
 * [#1819](https://github.com/shlinkio/shlink/issues/1819) Fix incorrect timeout when running DB commands during Shlink start-up.
+* [#1870](https://github.com/shlinkio/shlink/issues/1870) Make sure shared locks include the cache prefix when using Redis.
 
 
 ## [3.6.3] - 2023-06-14
diff --git a/composer.json b/composer.json
index ab187f55..4361797e 100644
--- a/composer.json
+++ b/composer.json
@@ -45,7 +45,7 @@
         "php-middleware/request-id": "^4.1",
         "pugx/shortid-php": "^1.1",
         "ramsey/uuid": "^4.7",
-        "shlinkio/shlink-common": "^5.5",
+        "shlinkio/shlink-common": "dev-main#5a8bd5a as 5.6",
         "shlinkio/shlink-config": "^2.4",
         "shlinkio/shlink-event-dispatcher": "^3.0",
         "shlinkio/shlink-importer": "^5.1",
diff --git a/config/autoload/locks.global.php b/config/autoload/locks.global.php
index 5e37e770..28426c6a 100644
--- a/config/autoload/locks.global.php
+++ b/config/autoload/locks.global.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
 use Shlinkio\Shlink\Common\Cache\RedisFactory;
+use Shlinkio\Shlink\Common\Lock\NamespacedStore;
 use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory;
 use Shlinkio\Shlink\Core\Config\EnvVars;
 use Symfony\Component\Lock;
@@ -22,11 +23,12 @@ return [
             Lock\Store\RedisStore::class => ConfigAbstractFactory::class,
             Lock\LockFactory::class => ConfigAbstractFactory::class,
             LOCAL_LOCK_FACTORY => ConfigAbstractFactory::class,
+            NamespacedStore::class => ConfigAbstractFactory::class,
         ],
         'aliases' => [
             'lock_store' => EnvVars::REDIS_SERVERS->existsInEnv() ? 'redis_lock_store' : 'local_lock_store',
 
-            'redis_lock_store' => Lock\Store\RedisStore::class,
+            'redis_lock_store' => NamespacedStore::class,
             'local_lock_store' => Lock\Store\FlockStore::class,
         ],
         'delegators' => [
@@ -39,6 +41,8 @@ return [
     ConfigAbstractFactory::class => [
         Lock\Store\FlockStore::class => ['config.locks.locks_dir'],
         Lock\Store\RedisStore::class => [RedisFactory::SERVICE_NAME],
+        NamespacedStore::class => [Lock\Store\RedisStore::class, 'config.cache.namespace'],
+
         Lock\LockFactory::class => ['lock_store'],
         LOCAL_LOCK_FACTORY => ['local_lock_store'],
     ],