From 6651211f02b5514c5ed94575d954f4e23a50a71f Mon Sep 17 00:00:00 2001 From: Kevin Anidjar Date: Sat, 28 Nov 2020 14:12:04 +0100 Subject: [PATCH 1/2] Redis: allow to pass connection name --- .../Foundation/Testing/Concerns/InteractsWithRedis.php | 1 + src/Illuminate/Redis/Connectors/PhpRedisConnector.php | 8 ++++++++ tests/Redis/RedisConnectorTest.php | 1 + 3 files changed, 10 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php index a68995b05a9d..1c679fb60197 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php @@ -57,6 +57,7 @@ public function setUpRedis() 'port' => $port, 'database' => 5, 'timeout' => 0.5, + 'name' => 'default', ], ]); } diff --git a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php index ba14ad87a928..090247feba18 100644 --- a/src/Illuminate/Redis/Connectors/PhpRedisConnector.php +++ b/src/Illuminate/Redis/Connectors/PhpRedisConnector.php @@ -102,6 +102,10 @@ protected function createClient(array $config) if (! empty($config['scan'])) { $client->setOption(Redis::OPT_SCAN, $config['scan']); } + + if (! empty($config['name'])) { + $client->client('SETNAME', $config['name']); + } }); } @@ -176,6 +180,10 @@ protected function createRedisClusterInstance(array $servers, array $options) if (! empty($options['failover'])) { $client->setOption(RedisCluster::OPT_SLAVE_FAILOVER, $options['failover']); } + + if (! empty($options['name'])) { + $client->client('SETNAME', $options['name']); + } }); } diff --git a/tests/Redis/RedisConnectorTest.php b/tests/Redis/RedisConnectorTest.php index 36b488582215..fbb899197b9e 100644 --- a/tests/Redis/RedisConnectorTest.php +++ b/tests/Redis/RedisConnectorTest.php @@ -41,6 +41,7 @@ public function testDefaultConfiguration() $phpRedisClient = $this->redis['phpredis']->connection()->client(); $this->assertEquals($host, $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); + $this->assertEquals("default", $phpRedisClient->client('GETNAME')); } public function testUrl() From 6137b0872aacaa13b8990d3f0c071c543d09a360 Mon Sep 17 00:00:00 2001 From: Kevin Anidjar Date: Sat, 28 Nov 2020 14:31:13 +0100 Subject: [PATCH 2/2] Fix style --- tests/Redis/RedisConnectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Redis/RedisConnectorTest.php b/tests/Redis/RedisConnectorTest.php index fbb899197b9e..ff5f93470e8d 100644 --- a/tests/Redis/RedisConnectorTest.php +++ b/tests/Redis/RedisConnectorTest.php @@ -41,7 +41,7 @@ public function testDefaultConfiguration() $phpRedisClient = $this->redis['phpredis']->connection()->client(); $this->assertEquals($host, $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); - $this->assertEquals("default", $phpRedisClient->client('GETNAME')); + $this->assertEquals('default', $phpRedisClient->client('GETNAME')); } public function testUrl()