2
2
3
3
namespace LaunchDarkly \Impl \Integrations ;
4
4
5
+ use Redis ;
6
+
5
7
/**
6
8
* @internal
7
9
*/
8
10
class PHPRedisFeatureRequester extends FeatureRequesterBase
9
11
{
10
- /** @var array */
11
- private $ _redisOptions ;
12
- /** @var \Redis */
13
- private $ _redisInstance ;
14
- /** @var string */
15
- private $ _prefix ;
12
+ private ?array $ redisOptions = null ;
13
+ private ?Redis $ redisInstance = null ;
14
+ private ?string $ prefix ;
16
15
17
- public function __construct ($ baseUri , $ sdkKey , $ options )
16
+ public function __construct (string $ baseUri , string $ sdkKey , array $ options )
18
17
{
19
18
parent ::__construct ($ baseUri , $ sdkKey , $ options );
20
19
21
- $ this ->_prefix = $ options ['redis_prefix ' ] ?? null ;
22
- if ($ this ->_prefix === null || $ this ->_prefix === '' ) {
23
- $ this ->_prefix = 'launchdarkly ' ;
20
+ /** @var ?string **/
21
+ $ this ->prefix = $ options ['redis_prefix ' ] ?? null ;
22
+ if ($ this ->prefix === null || $ this ->prefix === '' ) {
23
+ $ this ->prefix = 'launchdarkly ' ;
24
24
}
25
25
26
+ /** @var ?Redis */
26
27
$ client = $ this ->_options ['phpredis_client ' ] ?? null ;
27
- if ($ client instanceof \ Redis) {
28
- $ this ->_redisInstance = $ client ;
28
+ if ($ client instanceof Redis) {
29
+ $ this ->redisInstance = $ client ;
29
30
} else {
30
- $ this ->_redisOptions = [
31
+ $ this ->redisOptions = [
31
32
"timeout " => $ options ['redis_timeout ' ] ?? 5 ,
32
33
"host " => $ options ['redis_host ' ] ?? 'localhost ' ,
33
34
"port " => $ options ['redis_port ' ] ?? 6379 ,
@@ -39,37 +40,34 @@ public function __construct($baseUri, $sdkKey, $options)
39
40
protected function readItemString (string $ namespace , string $ key ): ?string
40
41
{
41
42
$ redis = $ this ->getConnection ();
42
- return $ redis ->hget ("$ this ->_prefix : $ namespace " , $ key );
43
+ return $ redis ->hget ("$ this ->prefix : $ namespace " , $ key );
43
44
}
44
45
45
46
protected function readItemStringList (string $ namespace ): ?array
46
47
{
47
48
$ redis = $ this ->getConnection ();
48
- $ raw = $ redis ->hgetall ("$ this ->_prefix : $ namespace " );
49
+ $ raw = $ redis ->hgetall ("$ this ->prefix : $ namespace " );
49
50
return $ raw ? array_values ($ raw ) : null ;
50
51
}
51
52
52
- /**
53
- * @return \Redis
54
- */
55
- protected function getConnection ()
53
+ protected function getConnection (): Redis
56
54
{
57
- if ($ this ->_redisInstance instanceof \ Redis) {
58
- return $ this ->_redisInstance ;
55
+ if ($ this ->redisInstance instanceof Redis) {
56
+ return $ this ->redisInstance ;
59
57
}
60
58
61
- $ redis = new \ Redis ();
59
+ $ redis = new Redis ();
62
60
$ redis ->pconnect (
63
- $ this ->_redisOptions ["host " ],
64
- $ this ->_redisOptions ["port " ],
65
- $ this ->_redisOptions ["timeout " ],
61
+ $ this ->redisOptions ["host " ],
62
+ $ this ->redisOptions ["port " ],
63
+ $ this ->redisOptions ["timeout " ],
66
64
'launchdarkly/php-server-sdk-redis-phpredis '
67
65
);
68
66
69
- if ($ this ->_redisOptions ['password ' ]) {
70
- $ redis ->auth ($ this ->_redisOptions ['password ' ]);
67
+ if ($ this ->redisOptions ['password ' ]) {
68
+ $ redis ->auth ($ this ->redisOptions ['password ' ]);
71
69
}
72
70
73
- return $ this ->_redisInstance = $ redis ;
71
+ return $ this ->redisInstance = $ redis ;
74
72
}
75
73
}
0 commit comments