Skip to content

Commit

Permalink
[8.x] Redis: allow to pass connection name (#35402)
Browse files Browse the repository at this point in the history
* Redis: allow to pass connection name

* Fix style

Co-authored-by: Kevin Anidjar <kevin.anidjar@total.com>
  • Loading branch information
kanidjar and Kevin Anidjar committed Nov 29, 2020
1 parent f33d3e5 commit d12b613
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Expand Up @@ -57,6 +57,7 @@ public function setUpRedis()
'port' => $port,
'database' => 5,
'timeout' => 0.5,
'name' => 'default',
],
]);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Expand Up @@ -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']);
}
});
}

Expand Down Expand Up @@ -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']);
}
});
}

Expand Down
1 change: 1 addition & 0 deletions tests/Redis/RedisConnectorTest.php
Expand Up @@ -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()
Expand Down

0 comments on commit d12b613

Please sign in to comment.