File tree Expand file tree Collapse file tree 2 files changed +29
-13
lines changed
tests/unit/Component/Tests/Cache Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -108,31 +108,26 @@ public function clear(): bool
108
108
*/
109
109
public function getMultiple (iterable $ keys , mixed $ default = null ): iterable
110
110
{
111
- foreach ($ keys as &$ key )
111
+ $ newKeys = [];
112
+ $ parsedKeys = [];
113
+ foreach ($ keys as $ key )
112
114
{
113
- $ key = $ this ->parseKey ($ key );
115
+ $ parsedKeys [] = $ this ->parseKey ($ key );
116
+ $ newKeys [] = $ key ;
114
117
}
115
- unset($ key );
116
- $ mgetResult = $ this ->redisManager ->getInstance ()->mget ($ keys );
118
+ $ mgetResult = $ this ->redisManager ->getInstance ()->mget ($ parsedKeys );
117
119
$ result = [];
118
120
if ($ mgetResult )
119
121
{
120
122
foreach ($ mgetResult as $ i => $ v )
121
123
{
122
- $ key = $ keys [$ i ];
123
-
124
- if ($ this ->prefix && str_starts_with ((string ) $ key , $ this ->prefix ))
125
- {
126
- $ key = substr ((string ) $ key , \strlen ($ this ->prefix ));
127
- }
128
-
129
124
if (false === $ v || null === $ v )
130
125
{
131
- $ result [$ key ] = $ default ;
126
+ $ result [$ newKeys [ $ i ] ] = $ default ;
132
127
}
133
128
else
134
129
{
135
- $ result [$ key ] = $ this ->decode ($ v );
130
+ $ result [$ newKeys [ $ i ] ] = $ this ->decode ($ v );
136
131
}
137
132
}
138
133
}
Original file line number Diff line number Diff line change @@ -230,6 +230,27 @@ public function testSetMultiple(string $name): void
230
230
Assert::assertEquals ($ values , $ getValues );
231
231
}
232
232
233
+ #[DataProvider('redisConnectionProvider ' )]
234
+ public function testSetMultipleKeys (string $ name ): void
235
+ {
236
+ if ('predis_cluster ' === $ name )
237
+ {
238
+ $ this ->expectExceptionMessage ('predis cluster not support setMultiple method ' );
239
+ }
240
+ $ value = bin2hex (random_bytes (8 ));
241
+
242
+ $ values = [
243
+ 'k1 ' => 'v1 ' . $ value ,
244
+ 'k2 ' => 'v2 ' . $ value ,
245
+ 'k3 ' => 'v3 ' . $ value ,
246
+ ];
247
+ $ cache = $ this ->getCacheHandler ($ name );
248
+
249
+ Assert::assertTrue ($ cache ->setMultiple ($ values ));
250
+ $ getValues = $ cache ->getMultiple ([0 => 'k1 ' , 2 => 'k2 ' , 'A ' => 'k3 ' ]);
251
+ Assert::assertEquals ($ values , $ getValues );
252
+ }
253
+
233
254
/**
234
255
* @testdox Set multiple TTL
235
256
*/
You can’t perform that action at this time.
0 commit comments