2222use function serialize ;
2323use function strpbrk ;
2424use function unserialize ;
25+ use function in_array ;
2526
2627/**
2728 * RedisCache stores cache data in a Redis.
@@ -43,26 +44,6 @@ public function __construct(private readonly ClientInterface $client)
4344 $ this ->connections = $ this ->client ->getConnection ();
4445 }
4546
46- /**
47- * Returns whether Predis cluster is used.
48- *
49- * @return bool Whether Predis cluster is used.
50- */
51- private function isCluster (): bool
52- {
53- /** @psalm-suppress MixedAssignment, PossibleRawObjectIteration */
54- foreach ($ this ->connections as $ connection ) {
55- /** @var StreamConnection $connection */
56- $ cluster = (new Client ($ connection ->getParameters ()))->info ('Cluster ' );
57- /** @psalm-suppress MixedArrayAccess */
58- if (isset ($ cluster ['Cluster ' ]['cluster_enabled ' ]) && 1 === (int )$ cluster ['Cluster ' ]['cluster_enabled ' ]) {
59- return true ;
60- }
61- }
62-
63- return false ;
64- }
65-
6647 public function get (string $ key , mixed $ default = null ): mixed
6748 {
6849 $ this ->validateKey ($ key );
@@ -71,7 +52,7 @@ public function get(string $key, mixed $default = null): mixed
7152 return $ value === null ? $ default : unserialize ($ value );
7253 }
7354
74- public function set (string $ key , mixed $ value , null | int |DateInterval $ ttl = null ): bool
55+ public function set (string $ key , mixed $ value , int |DateInterval | null $ ttl = null ): bool
7556 {
7657 $ ttl = $ this ->normalizeTtl ($ ttl );
7758
@@ -145,7 +126,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
145126 return $ values ;
146127 }
147128
148- public function setMultiple (iterable $ values , null | int |DateInterval $ ttl = null ): bool
129+ public function setMultiple (iterable $ values , int |DateInterval | null $ ttl = null ): bool
149130 {
150131 $ values = $ this ->iterableToArray ($ values );
151132 $ keys = array_map (\strval (...), array_keys ($ values ));
@@ -164,7 +145,7 @@ public function setMultiple(iterable $values, null|int|DateInterval $ttl = null)
164145 $ results = [];
165146 if ($ this ->isCluster ()) {
166147 foreach ($ serializeValues as $ key => $ value ) {
167- $ this ->set ((string )$ key , $ value , $ this ->isInfinityTtl ($ ttl ) ? null : $ ttl );
148+ $ this ->set ((string ) $ key , $ value , $ this ->isInfinityTtl ($ ttl ) ? null : $ ttl );
168149 }
169150 } else {
170151 if ($ this ->isInfinityTtl ($ ttl )) {
@@ -176,14 +157,14 @@ public function setMultiple(iterable $values, null|int|DateInterval $ttl = null)
176157 $ this ->client ->mset ($ serializeValues );
177158
178159 foreach ($ keys as $ key ) {
179- $ this ->client ->expire ($ key , (int )$ ttl );
160+ $ this ->client ->expire ($ key , (int ) $ ttl );
180161 }
181162
182163 /** @var array|null $results */
183164 $ results = $ this ->client ->exec ();
184165 }
185166
186- return !in_array (null , (array )$ results , true );
167+ return !in_array (null , (array ) $ results , true );
187168 }
188169
189170 public function deleteMultiple (iterable $ keys ): bool
@@ -210,14 +191,34 @@ public function has(string $key): bool
210191 return $ ttl > 0 || $ ttl === -1 ;
211192 }
212193
194+ /**
195+ * Returns whether Predis cluster is used.
196+ *
197+ * @return bool Whether Predis cluster is used.
198+ */
199+ private function isCluster (): bool
200+ {
201+ /** @psalm-suppress MixedAssignment, PossibleRawObjectIteration */
202+ foreach ($ this ->connections as $ connection ) {
203+ /** @var StreamConnection $connection */
204+ $ cluster = (new Client ($ connection ->getParameters ()))->info ('Cluster ' );
205+ /** @psalm-suppress MixedArrayAccess */
206+ if (isset ($ cluster ['Cluster ' ]['cluster_enabled ' ]) && 1 === (int ) $ cluster ['Cluster ' ]['cluster_enabled ' ]) {
207+ return true ;
208+ }
209+ }
210+
211+ return false ;
212+ }
213+
213214 /**
214215 * Normalizes cache TTL handling `null` value, strings and {@see DateInterval} objects.
215216 *
216217 * @param DateInterval|int|string|null $ttl The raw TTL.
217218 *
218219 * @return int|null TTL value as UNIX timestamp.
219220 */
220- private function normalizeTtl (null | int |string |DateInterval $ ttl ): ?int
221+ private function normalizeTtl (int |string |DateInterval | null $ ttl ): ?int
221222 {
222223 if ($ ttl === null ) {
223224 return null ;
0 commit comments