5
5
namespace Prometheus \Storage \RedisClients ;
6
6
7
7
use Predis \Client ;
8
- use Predis \Configuration \Option \Prefix ;
9
8
10
9
class Predis implements RedisClient
11
10
{
12
11
private const OPTIONS_MAP = [
13
- RedisClient::OPT_PREFIX => Prefix::class ,
12
+ RedisClient::OPT_PREFIX => ' prefix ' ,
14
13
];
15
14
16
15
private $ client ;
17
16
18
- private $ prefix = '' ;
17
+ private $ options = [] ;
19
18
20
- public function __construct (Client $ redis )
19
+ public function __construct (Client $ redis, array $ options )
21
20
{
22
21
$ this ->client = $ redis ;
22
+
23
+ $ this ->options = $ options ;
23
24
}
24
25
25
- public static function create (array $ options ): self
26
+ public static function create (array $ parameters , array $ options ): self
26
27
{
27
- $ this ->prefix = $ options ['prefix ' ] ?? '' ;
28
- $ redisClient = new Client ($ options , ['prefix ' => $ options ['prefix ' ] ?? '' ]);
28
+ $ redisClient = new Client ($ parameters , $ options );
29
29
30
- return new self ($ redisClient );
30
+ return new self ($ redisClient, $ options );
31
31
}
32
32
33
33
public function getOption (int $ option ): mixed
@@ -38,19 +38,17 @@ public function getOption(int $option): mixed
38
38
39
39
$ mappedOption = self ::OPTIONS_MAP [$ option ];
40
40
41
- return $ this ->client -> getOptions ()-> $ mappedOption ;
41
+ return $ this ->options [ $ mappedOption] ?? null ;
42
42
}
43
43
44
- public function eval (string $ script , array $ args = [], int $ num_keys = 0 ): mixed
44
+ public function eval (string $ script , array $ args = [], int $ num_keys = 0 ): void
45
45
{
46
- return $ this ->client ->eval ($ script , $ num_keys , ...$ args );
46
+ $ this ->client ->eval ($ script , $ num_keys , ...$ args );
47
47
}
48
48
49
- public function set (string $ key , mixed $ value , mixed $ options = null ): string | bool
49
+ public function set (string $ key , mixed $ value , mixed $ options = null ): void
50
50
{
51
- $ result = $ this ->client ->set ($ key , $ value , ...$ this ->flattenFlags ($ options ));
52
-
53
- return (string ) $ result ;
51
+ $ this ->client ->set ($ key , $ value , ...$ this ->flattenFlags ($ options ));
54
52
}
55
53
56
54
private function flattenFlags (array $ flags ): array
@@ -68,9 +66,9 @@ private function flattenFlags(array $flags): array
68
66
return $ result ;
69
67
}
70
68
71
- public function setNx (string $ key , mixed $ value ): bool
69
+ public function setNx (string $ key , mixed $ value ): void
72
70
{
73
- return $ this ->client ->setnx ($ key , $ value ) === 1 ;
71
+ $ this ->client ->setnx ($ key , $ value ) === 1 ;
74
72
}
75
73
76
74
public function hSetNx (string $ key , string $ field , mixed $ value ): bool
@@ -98,16 +96,9 @@ public function get(string $key): mixed
98
96
return $ this ->client ->get ($ key );
99
97
}
100
98
101
- public function del (array |string $ key , string ...$ other_keys ): int |false
102
- {
103
- return $ this ->client ->del ($ key , ...$ other_keys );
104
- }
105
-
106
- public function getPrefix (): string
99
+ public function del (array |string $ key , string ...$ other_keys ): void
107
100
{
108
- $ key = RedisClient::OPT_PREFIX ;
109
-
110
- return $ this ->prefix ;
101
+ $ this ->client ->del ($ key , ...$ other_keys );
111
102
}
112
103
113
104
public function ensureOpenConnection (): void
0 commit comments