diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 301180a385bc..21d80fccfbfd 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -181,6 +181,16 @@ public function createSubscription($channels, Closure $callback, $method = 'subs // } + /** + * Disconnects from the Redis instance. + * + * @return void + */ + public function disconnect() + { + $this->client->close(); + } + /** * Pass other method calls down to the underlying client. * diff --git a/tests/Redis/InteractsWithRedis.php b/tests/Redis/InteractsWithRedis.php index a453ef0f1e7f..d3b6c3307a74 100644 --- a/tests/Redis/InteractsWithRedis.php +++ b/tests/Redis/InteractsWithRedis.php @@ -27,8 +27,8 @@ public function setUpRedis() return; } - foreach (['predis', 'phpredis'] as $driver) { - $this->redis[$driver] = new RedisManager($driver, [ + foreach ($this->redisDriverProvider() as $driver) { + $this->redis[$driver[0]] = new RedisManager($driver[0], [ 'cluster' => false, 'default' => [ 'host' => $host, @@ -53,18 +53,23 @@ public function setUpRedis() public function tearDownRedis() { - if ($this->redis) { - $this->redis['predis']->connection()->flushdb(); - $this->redis['predis']->connection()->disconnect(); - $this->redis['phpredis']->connection()->close(); + $this->redis['predis']->connection()->flushdb(); + + foreach ($this->redisDriverProvider() as $driver) { + $this->redis[$driver[0]]->connection()->disconnect(); } } public function redisDriverProvider() { - return [ + $providers = [ ['predis'], - ['phpredis'], ]; + + if (extension_loaded('redis')) { + $providers[] = ['phpredis']; + } + + return $providers; } }