mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
Fixed Redis::select is not work expected.
This commit is contained in:
parent
83b578e4e1
commit
cde44c380b
@ -45,6 +45,9 @@ class Redis
|
||||
// Release connection.
|
||||
if (! $hasContextConnection) {
|
||||
if ($this->shouldUseSameConnection($name)) {
|
||||
if ($name == 'select') {
|
||||
$connection->setDbChanged(true);
|
||||
}
|
||||
// Should storage the connection to coroutine context, then use defer() to release the connection.
|
||||
Context::set($this->getContextKey(), $connection);
|
||||
defer(function () use ($connection) {
|
||||
@ -69,6 +72,7 @@ class Redis
|
||||
return in_array($methodName, [
|
||||
'multi',
|
||||
'pipeline',
|
||||
'select',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,11 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $dbChanged;
|
||||
|
||||
public function __construct(ContainerInterface $container, Pool $pool, array $config)
|
||||
{
|
||||
parent::__construct($container, $pool);
|
||||
@ -86,4 +91,21 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function release(): void
|
||||
{
|
||||
if ($this->dbChanged) {
|
||||
// Select the origin db after execute select.
|
||||
$this->select($this->config['db'] ?? 0);
|
||||
}
|
||||
parent::release();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $dbChanged
|
||||
*/
|
||||
public function setDbChanged(bool $dbChanged): void
|
||||
{
|
||||
$this->dbChanged = $dbChanged;
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,9 @@ class RedisTest extends TestCase
|
||||
|
||||
$this->assertTrue($redis->connect('127.0.0.1', 6379, 0.0));
|
||||
}
|
||||
|
||||
public function testRedisCommand()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user