diff --git a/src/Storage/Adapter/RedisResourceManager.php b/src/Storage/Adapter/RedisResourceManager.php index dd0db2c90..31e56b4df 100644 --- a/src/Storage/Adapter/RedisResourceManager.php +++ b/src/Storage/Adapter/RedisResourceManager.php @@ -332,7 +332,7 @@ public function setResource($id, $resource) $resource = array_merge( $defaults, [ - 'resource' => $resource, + 'resource' => $resource, 'initialized' => isset($resource->socket), ] ); @@ -629,15 +629,21 @@ public function setPassword($id, $password) */ public function setDatabase($id, $database) { + $database = (int) $database; + if (!$this->hasResource($id)) { return $this->setResource($id, [ - 'database' => (int) $database, + 'database' => $database, ]); } $resource = & $this->resources[$id]; - $resource['database'] = $database; - $resource['initialized'] = false; + if ($resource['resource'] instanceof RedisResource && $resource['initialized']) { + $resource['resource']->select($database); + } + + $resource['database'] = $database; + return $this; } }