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
108108 */
109109 public function getMultiple (iterable $ keys , mixed $ default = null ): iterable
110110 {
111- foreach ($ keys as &$ key )
111+ $ newKeys = [];
112+ $ parsedKeys = [];
113+ foreach ($ keys as $ key )
112114 {
113- $ key = $ this ->parseKey ($ key );
115+ $ parsedKeys [] = $ this ->parseKey ($ key );
116+ $ newKeys [] = $ key ;
114117 }
115- unset($ key );
116- $ mgetResult = $ this ->redisManager ->getInstance ()->mget ($ keys );
118+ $ mgetResult = $ this ->redisManager ->getInstance ()->mget ($ parsedKeys );
117119 $ result = [];
118120 if ($ mgetResult )
119121 {
120122 foreach ($ mgetResult as $ i => $ v )
121123 {
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-
129124 if (false === $ v || null === $ v )
130125 {
131- $ result [$ key ] = $ default ;
126+ $ result [$ newKeys [ $ i ] ] = $ default ;
132127 }
133128 else
134129 {
135- $ result [$ key ] = $ this ->decode ($ v );
130+ $ result [$ newKeys [ $ i ] ] = $ this ->decode ($ v );
136131 }
137132 }
138133 }
Original file line number Diff line number Diff line change @@ -230,6 +230,27 @@ public function testSetMultiple(string $name): void
230230 Assert::assertEquals ($ values , $ getValues );
231231 }
232232
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+
233254 /**
234255 * @testdox Set multiple TTL
235256 */
You can’t perform that action at this time.
0 commit comments