From 111034eba3468ef47293f7e2d67f785a3482f271 Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Thu, 9 Nov 2017 17:16:45 +0700 Subject: [PATCH 1/3] [Redis] add custom database index --- pkg/redis/PhpRedis.php | 3 +++ pkg/redis/RedisConnectionFactory.php | 2 ++ pkg/redis/Symfony/RedisTransportFactory.php | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/pkg/redis/PhpRedis.php b/pkg/redis/PhpRedis.php index 139fa94dd..71ead40d4 100644 --- a/pkg/redis/PhpRedis.php +++ b/pkg/redis/PhpRedis.php @@ -26,6 +26,7 @@ public function __construct(array $config) 'reserved' => null, 'retry_interval' => null, 'persisted' => false, + 'database' => 0, ], $config); } @@ -80,6 +81,8 @@ public function connect() $this->config['retry_interval'] ); } + + $this->redis->select($this->config['database']); } return $this->redis; diff --git a/pkg/redis/RedisConnectionFactory.php b/pkg/redis/RedisConnectionFactory.php index 122bf0bef..021a448f4 100644 --- a/pkg/redis/RedisConnectionFactory.php +++ b/pkg/redis/RedisConnectionFactory.php @@ -27,6 +27,7 @@ class RedisConnectionFactory implements PsrConnectionFactory * 'vendor' => 'The library used internally to interact with Redis server * 'persisted' => bool, Whether it use single persisted connection or open a new one for every context * 'lazy' => the connection will be performed as later as possible, if the option set to true + * 'database' => Database index to select when connected (default value: 0) * ]. * * or @@ -139,6 +140,7 @@ private function defaultConfig() 'vendor' => 'phpredis', 'persisted' => false, 'lazy' => true, + 'database' => 0, ]; } } diff --git a/pkg/redis/Symfony/RedisTransportFactory.php b/pkg/redis/Symfony/RedisTransportFactory.php index 092e3baf8..f24df84e4 100644 --- a/pkg/redis/Symfony/RedisTransportFactory.php +++ b/pkg/redis/Symfony/RedisTransportFactory.php @@ -54,6 +54,10 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->defaultTrue() ->info('the connection will be performed as later as possible, if the option set to true') ->end() + ->integerNode('database') + ->defaultValue(0) + ->info('Database index to select when connected.') + ->end() ; } From 2acee9960cd927902e4a69e820dac752da272e21 Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Thu, 9 Nov 2017 17:37:35 +0700 Subject: [PATCH 2/3] fix tests --- pkg/redis/Tests/RedisConnectionFactoryConfigTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php index f3375e0de..87316625c 100644 --- a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php +++ b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php @@ -71,6 +71,7 @@ public static function provideConfigs() 'vendor' => 'phpredis', 'persisted' => false, 'lazy' => true, + 'database' => 0, ], ]; @@ -85,6 +86,7 @@ public static function provideConfigs() 'vendor' => 'phpredis', 'persisted' => false, 'lazy' => true, + 'database' => 0, ], ]; @@ -114,6 +116,7 @@ public static function provideConfigs() 'persisted' => true, 'lazy' => false, 'foo' => 'bar', + 'database' => 0, ], ]; @@ -129,6 +132,7 @@ public static function provideConfigs() 'persisted' => false, 'lazy' => true, 'foo' => 'bar', + 'database' => 0, ], ]; } From cd1542ace0cd21c99e66b23a58a502a5f6ea05ce Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Thu, 9 Nov 2017 17:43:02 +0700 Subject: [PATCH 3/3] fix tests --- pkg/redis/Tests/RedisConnectionFactoryConfigTest.php | 1 + pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php index 87316625c..51c185b9b 100644 --- a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php +++ b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php @@ -101,6 +101,7 @@ public static function provideConfigs() 'vendor' => 'phpredis', 'persisted' => false, 'lazy' => true, + 'database' => 0, ], ]; diff --git a/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php b/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php index 1b4175e6a..ca7d402c8 100644 --- a/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php +++ b/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php @@ -58,6 +58,7 @@ public function testShouldAllowAddConfiguration() 'vendor' => 'phpredis', 'persisted' => true, 'lazy' => false, + 'database' => 0, ], $config); }