55namespace Prometheus \Storage \RedisClients ;
66
77use Predis \Client ;
8- use Predis \Configuration \Option \Prefix ;
98
109class Predis implements RedisClient
1110{
1211 private const OPTIONS_MAP = [
13- RedisClient::OPT_PREFIX => Prefix::class ,
12+ RedisClient::OPT_PREFIX => ' prefix ' ,
1413 ];
1514
1615 private $ client ;
1716
18- private $ prefix = '' ;
17+ private $ options = [] ;
1918
20- public function __construct (Client $ redis )
19+ public function __construct (Client $ redis, array $ options )
2120 {
2221 $ this ->client = $ redis ;
22+
23+ $ this ->options = $ options ;
2324 }
2425
25- public static function create (array $ options ): self
26+ public static function create (array $ parameters , array $ options ): self
2627 {
27- $ this ->prefix = $ options ['prefix ' ] ?? '' ;
28- $ redisClient = new Client ($ options , ['prefix ' => $ options ['prefix ' ] ?? '' ]);
28+ $ redisClient = new Client ($ parameters , $ options );
2929
30- return new self ($ redisClient );
30+ return new self ($ redisClient, $ options );
3131 }
3232
3333 public function getOption (int $ option ): mixed
@@ -38,19 +38,17 @@ public function getOption(int $option): mixed
3838
3939 $ mappedOption = self ::OPTIONS_MAP [$ option ];
4040
41- return $ this ->client -> getOptions ()-> $ mappedOption ;
41+ return $ this ->options [ $ mappedOption] ?? null ;
4242 }
4343
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
4545 {
46- return $ this ->client ->eval ($ script , $ num_keys , ...$ args );
46+ $ this ->client ->eval ($ script , $ num_keys , ...$ args );
4747 }
4848
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
5050 {
51- $ result = $ this ->client ->set ($ key , $ value , ...$ this ->flattenFlags ($ options ));
52-
53- return (string ) $ result ;
51+ $ this ->client ->set ($ key , $ value , ...$ this ->flattenFlags ($ options ));
5452 }
5553
5654 private function flattenFlags (array $ flags ): array
@@ -68,9 +66,9 @@ private function flattenFlags(array $flags): array
6866 return $ result ;
6967 }
7068
71- public function setNx (string $ key , mixed $ value ): bool
69+ public function setNx (string $ key , mixed $ value ): void
7270 {
73- return $ this ->client ->setnx ($ key , $ value ) === 1 ;
71+ $ this ->client ->setnx ($ key , $ value ) === 1 ;
7472 }
7573
7674 public function hSetNx (string $ key , string $ field , mixed $ value ): bool
@@ -98,16 +96,9 @@ public function get(string $key): mixed
9896 return $ this ->client ->get ($ key );
9997 }
10098
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
107100 {
108- $ key = RedisClient::OPT_PREFIX ;
109-
110- return $ this ->prefix ;
101+ $ this ->client ->del ($ key , ...$ other_keys );
111102 }
112103
113104 public function ensureOpenConnection (): void
0 commit comments