Skip to content

Commit a40016c

Browse files
prepare 3.9.1 release (#152)
1 parent 0b7c1ef commit a40016c

File tree

3 files changed

+123
-5
lines changed

3 files changed

+123
-5
lines changed

src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public function __construct($baseUri, $sdkKey, $options)
1616
{
1717
parent::__construct($baseUri, $sdkKey, $options);
1818

19-
$this->_prefix = isset($options['redis_prefix']) ? $options['redis_prefix'] : 'launchdarkly';
19+
$this->_prefix = isset($options['redis_prefix']) ? $options['redis_prefix'] : null;
20+
if ($this->_prefix === null || $this->_prefix === '') {
21+
$this->_prefix = 'launchdarkly';
22+
}
2023

2124
if (isset($this->_options['phpredis_client']) && $this->_options['phpredis_client'] instanceof \Redis) {
2225
$this->_redisInstance = $this->_options['phpredis_client'];
@@ -32,13 +35,13 @@ public function __construct($baseUri, $sdkKey, $options)
3235
protected function readItemString($namespace, $key)
3336
{
3437
$redis = $this->getConnection();
35-
return $redis->hget($namespace, $key);
38+
return $redis->hget("$this->_prefix:$namespace", $key);
3639
}
3740

3841
protected function readItemStringList($namespace)
3942
{
4043
$redis = $this->getConnection();
41-
$raw = $redis->hgetall($namespace);
44+
$raw = $redis->hgetall("$this->_prefix:$namespace");
4245
return $raw ? array_values($raw) : null;
4346
}
4447

@@ -56,9 +59,8 @@ protected function getConnection()
5659
$this->_redisOptions["host"],
5760
$this->_redisOptions["port"],
5861
$this->_redisOptions["timeout"],
59-
'x'
62+
'LaunchDarkly'
6063
);
61-
$redis->setOption(\Redis::OPT_PREFIX, "$this->_prefix:"); // use custom prefix on all keys
6264
return $this->_redisInstance = $redis;
6365
}
6466
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace LaunchDarkly\Tests;
4+
5+
use LaunchDarkly\Integrations\PHPRedis;
6+
7+
/**
8+
* @requires extension redis
9+
*/
10+
class PHPRedisFeatureRequesterWithClientTest extends FeatureRequesterTestBase
11+
{
12+
const CLIENT_PREFIX = 'clientprefix';
13+
const LD_PREFIX = 'ldprefix';
14+
15+
/** @var \Redis */
16+
private static $redisClient;
17+
18+
public static function setUpBeforeClass()
19+
{
20+
if (!static::isSkipDatabaseTests()) {
21+
$redis = new \Redis();
22+
$redis->connect('127.0.0.1', 6379);
23+
$redis->setOption(\Redis::OPT_PREFIX, self::CLIENT_PREFIX);
24+
self::$redisClient = $redis;
25+
26+
// Setting a prefix parameter on the Redis client causes it to prepend
27+
// that string to every key *in addition to* the other prefix that the SDK
28+
// integration is applying (LD_PREFIX). This is done transparently so we
29+
// do not need to add CLIENT_PREFIX in putItem below. We're doing it so we
30+
// can be sure that the PHPRedisFeatureRequester really is using the same
31+
// client we passed to it; if it didn't, the tests would fail because
32+
// putItem was creating keys with both prefixes but PHPRedisFeatureRequester
33+
// was looking for keys with only one prefix.
34+
}
35+
}
36+
37+
protected function isDatabaseTest()
38+
{
39+
return true;
40+
}
41+
42+
protected function makeRequester()
43+
{
44+
$factory = PHPRedis::featureRequester();
45+
return $factory('', '', array(
46+
'redis_prefix' => self::LD_PREFIX,
47+
'phpredis_client' => self::$redisClient
48+
));
49+
}
50+
51+
protected function putItem($namespace, $key, $version, $json)
52+
{
53+
self::$redisClient->hset(self::LD_PREFIX . ":$namespace", $key, $json);
54+
}
55+
56+
protected function deleteExistingData()
57+
{
58+
self::$redisClient->flushdb();
59+
}
60+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace LaunchDarkly\Tests;
4+
5+
use LaunchDarkly\Integrations\Redis;
6+
use Predis\Client;
7+
8+
class RedisFeatureRequesterWithClientTest extends FeatureRequesterTestBase
9+
{
10+
const CLIENT_PREFIX = 'clientprefix';
11+
const LD_PREFIX = 'ldprefix';
12+
13+
/** @var ClientInterface */
14+
private static $predisClient;
15+
16+
public static function setUpBeforeClass()
17+
{
18+
if (!static::isSkipDatabaseTests()) {
19+
self::$predisClient = new Client(array(), array(
20+
'prefix' => self::CLIENT_PREFIX
21+
));
22+
// Setting a prefix parameter on the Predis\Client causes it to prepend
23+
// that string to every key *in addition to* the other prefix that the SDK
24+
// integration is applying (LD_PREFIX). This is done transparently so we
25+
// do not need to add CLIENT_PREFIX in putItem below. We're doing it so we
26+
// can be sure that the RedisFeatureRequester really is using the same
27+
// client we passed to it; if it didn't, the tests would fail because
28+
// putItem was creating keys with both prefixes but RedisFeatureRequester
29+
// was looking for keys with only one prefix.
30+
}
31+
}
32+
33+
protected function isDatabaseTest()
34+
{
35+
return true;
36+
}
37+
38+
protected function makeRequester()
39+
{
40+
$factory = Redis::featureRequester();
41+
return $factory('', '', array(
42+
'redis_prefix' => self::LD_PREFIX,
43+
'predis_client' => self::$predisClient
44+
));
45+
}
46+
47+
protected function putItem($namespace, $key, $version, $json)
48+
{
49+
self::$predisClient->hset(self::LD_PREFIX . ":$namespace", $key, $json);
50+
}
51+
52+
protected function deleteExistingData()
53+
{
54+
self::$predisClient->flushdb();
55+
}
56+
}

0 commit comments

Comments
 (0)