@@ -24,80 +24,86 @@ public function __construct(array $config)
2424 'port ' => null ,
2525 'pass ' => null ,
2626 'user ' => null ,
27- 'timeout ' => null ,
27+ 'timeout ' => .0 ,
2828 'reserved ' => null ,
2929 'retry_interval ' => null ,
3030 'persisted ' => false ,
3131 'database ' => 0 ,
3232 ], $ config );
33+
34+ var_dump ($ this ->config );
3335 }
3436
3537 /**
3638 * {@inheritdoc}
3739 */
38- public function lpush ($ key , $ value )
40+ public function lpush (string $ key , string $ value ): int
3941 {
40- if (false == $ this ->redis ->lPush ($ key , $ value )) {
41- throw new ServerException ($ this ->redis ->getLastError ());
42- }
42+ return $ this ->redis ->lPush ($ key , $ value );
4343 }
4444
4545 /**
4646 * {@inheritdoc}
4747 */
48- public function brpop ($ key , $ timeout )
48+ public function brpop (array $ keys , int $ timeout ): ? RedisResult
4949 {
50- if ($ result = $ this ->redis ->brPop ([ $ key ] , $ timeout )) {
51- return $ result [1 ] ;
50+ if ($ result = $ this ->redis ->brPop ($ keys , $ timeout )) {
51+ return new RedisResult ( $ result [0 ], $ result [ 1 ]) ;
5252 }
53+
54+ return null ;
5355 }
5456
5557 /**
5658 * {@inheritdoc}
5759 */
58- public function rpop ($ key )
60+ public function rpop (string $ key ): ? RedisResult
5961 {
60- return $ this ->redis ->rPop ($ key );
62+ if ($ message = $ this ->redis ->rPop ($ key )) {
63+ return new RedisResult ($ key , $ message );
64+ }
65+
66+ return null ;
6167 }
6268
6369 /**
6470 * {@inheritdoc}
6571 */
66- public function connect ()
72+ public function connect (): void
6773 {
68- if (false == $ this ->redis ) {
69- $ this -> redis = new \ Redis () ;
70-
71- if ( $ this -> config [ ' persisted ' ]) {
72- $ this ->redis -> pconnect (
73- $ this -> config [ ' host ' ],
74- $ this ->config ['port ' ],
75- $ this ->config [ ' timeout ' ]
76- );
77- } else {
78- $ this ->redis -> connect (
79- $ this -> config [ ' host ' ],
80- $ this -> config [ ' port ' ],
81- $ this ->config [ ' timeout ' ],
82- $ this ->config ['reserved ' ],
83- $ this ->config ['retry_interval ' ]
84- );
85- }
86-
87- if ( $ this -> config [ ' pass ' ]) {
88- $ this -> redis -> auth ( $ this -> config [ ' pass ' ]);
89- }
90-
91- $ this ->redis ->select ($ this ->config ['database ' ]);
74+ if ($ this ->redis ) {
75+ return ;
76+ }
77+
78+ $ this ->redis = new \ Redis ();
79+
80+ if ( $ this ->config ['persisted ' ]) {
81+ $ this ->redis -> pconnect (
82+ $ this -> config [ ' host ' ],
83+ $ this -> config [ ' port ' ],
84+ $ this ->config [ ' timeout ' ]
85+ );
86+ } else {
87+ $ this ->redis -> connect (
88+ $ this ->config ['host ' ],
89+ $ this ->config ['port ' ],
90+ $ this -> config [ ' timeout ' ],
91+ $ this -> config [ ' reserved ' ],
92+ $ this -> config [ ' retry_interval ' ]
93+ );
94+ }
95+
96+ if ( $ this -> config [ ' pass ' ]) {
97+ $ this ->redis ->auth ($ this ->config ['pass ' ]);
9298 }
9399
94- return $ this ->redis ;
100+ $ this ->redis -> select ( $ this -> config [ ' database ' ]) ;
95101 }
96102
97103 /**
98104 * {@inheritdoc}
99105 */
100- public function disconnect ()
106+ public function disconnect (): void
101107 {
102108 if ($ this ->redis ) {
103109 $ this ->redis ->close ();
@@ -107,7 +113,7 @@ public function disconnect()
107113 /**
108114 * {@inheritdoc}
109115 */
110- public function del ($ key )
116+ public function del (string $ key ): void
111117 {
112118 $ this ->redis ->del ($ key );
113119 }
0 commit comments