Skip to content

Commit 049d22a

Browse files
authored
Merge pull request #258 from IndraGunawan/redis-database
[Redis] add custom database index
2 parents db598d9 + 21a1e4c commit 049d22a

5 files changed

+15
-0
lines changed

pkg/redis/PhpRedis.php

+3
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;

pkg/redis/RedisConnectionFactory.php

+2
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
}

pkg/redis/Symfony/RedisTransportFactory.php

+4
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

pkg/redis/Tests/RedisConnectionFactoryConfigTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static function provideConfigs()
7171
'vendor' => 'phpredis',
7272
'persisted' => false,
7373
'lazy' => true,
74+
'database' => 0,
7475
],
7576
];
7677

@@ -85,6 +86,7 @@ public static function provideConfigs()
8586
'vendor' => 'phpredis',
8687
'persisted' => false,
8788
'lazy' => true,
89+
'database' => 0,
8890
],
8991
];
9092

@@ -99,6 +101,7 @@ public static function provideConfigs()
99101
'vendor' => 'phpredis',
100102
'persisted' => false,
101103
'lazy' => true,
104+
'database' => 0,
102105
],
103106
];
104107

@@ -114,6 +117,7 @@ public static function provideConfigs()
114117
'persisted' => true,
115118
'lazy' => false,
116119
'foo' => 'bar',
120+
'database' => 0,
117121
],
118122
];
119123

@@ -129,6 +133,7 @@ public static function provideConfigs()
129133
'persisted' => false,
130134
'lazy' => true,
131135
'foo' => 'bar',
136+
'database' => 0,
132137
],
133138
];
134139
}

pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function testShouldAllowAddConfiguration()
5858
'vendor' => 'phpredis',
5959
'persisted' => true,
6060
'lazy' => false,
61+
'database' => 0,
6162
], $config);
6263
}
6364

0 commit comments

Comments
 (0)