Skip to content

Commit e89bd6d

Browse files
committed
[Redis] add custom database index
1 parent 020cec7 commit e89bd6d

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

PhpRedis.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(array $config)
2626
'reserved' => null,
2727
'retry_interval' => null,
2828
'persisted' => false,
29+
'database' => 0,
2930
], $config);
3031
}
3132

@@ -80,6 +81,8 @@ public function connect()
8081
$this->config['retry_interval']
8182
);
8283
}
84+
85+
$this->redis->select($this->config['database']);
8386
}
8487

8588
return $this->redis;

RedisConnectionFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class RedisConnectionFactory implements PsrConnectionFactory
2727
* 'vendor' => 'The library used internally to interact with Redis server
2828
* 'persisted' => bool, Whether it use single persisted connection or open a new one for every context
2929
* 'lazy' => the connection will be performed as later as possible, if the option set to true
30+
* 'database' => Database index to select when connected (default value: 0)
3031
* ].
3132
*
3233
* or
@@ -139,6 +140,7 @@ private function defaultConfig()
139140
'vendor' => 'phpredis',
140141
'persisted' => false,
141142
'lazy' => true,
143+
'database' => 0,
142144
];
143145
}
144146
}

Symfony/RedisTransportFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function addConfiguration(ArrayNodeDefinition $builder)
5454
->defaultTrue()
5555
->info('the connection will be performed as later as possible, if the option set to true')
5656
->end()
57+
->integerNode('database')
58+
->defaultValue(0)
59+
->info('Database index to select when connected.')
60+
->end()
5761
;
5862
}
5963

0 commit comments

Comments
 (0)