Skip to content

Commit

Permalink
feature #19894 [Cache] Add "persistent_id" option to RedisAdapter::cr…
Browse files Browse the repository at this point in the history
…eateConnection() (nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Cache] Add "persistent_id" option to RedisAdapter::createConnection()

| Q             | A
| ------------- | ---
| Branch?       | master
| New feature?  | yes
| Tests pass?   | yes
| License       | MIT

Commits
-------

3ee02a0 [Cache] Add persistent_id option to RedisAdapter::createConnection()
  • Loading branch information
fabpot committed Sep 13, 2016
2 parents 0954f3d + 3ee02a0 commit e5088ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Expand Up @@ -25,6 +25,7 @@ class RedisAdapter extends AbstractAdapter
private static $defaultConnectionOptions = array(
'class' => null,
'persistent' => 0,
'persistent_id' => null,
'timeout' => 0,
'read_timeout' => 0,
'retry_interval' => 0,
Expand Down Expand Up @@ -99,9 +100,9 @@ public static function createConnection($dsn, array $options = array())
$class = null === $params['class'] ? (extension_loaded('redis') ? \Redis::class : \Predis\Client::class) : $params['class'];

if (is_a($class, \Redis::class, true)) {
$connect = empty($params['persistent']) ? 'connect' : 'pconnect';
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
$redis = new $class();
@$redis->{$connect}($params['host'], $params['port'], $params['timeout'], null, $params['retry_interval']);
@$redis->{$connect}($params['host'], $params['port'], $params['timeout'], $params['persistent_id'], $params['retry_interval']);

if (@!$redis->isConnected()) {
$e = ($e = error_get_last()) && preg_match('/^Redis::p?connect\(\): (.*)/', $e['message'], $e) ? sprintf(' (%s)', $e[1]) : '';
Expand Down
Expand Up @@ -39,6 +39,7 @@ public function testCreateConnection()
'class' => 'Predis\Client',
'timeout' => 3,
'persistent' => 0,
'persistent_id' => null,
'read_timeout' => 0,
'retry_interval' => 0,
'database' => '1',
Expand Down

0 comments on commit e5088ac

Please sign in to comment.