@@ -77,23 +77,26 @@ public function clear(): bool
7777 */
7878 public function getMultiple (iterable $ keys , mixed $ default = null ): iterable
7979 {
80- foreach ($ keys as &$ key )
80+ $ newKeys = [];
81+ $ parsedKeys = [];
82+ foreach ($ keys as $ key )
8183 {
82- $ key = $ this ->parseKey ($ key );
84+ $ parsedKeys [] = $ this ->parseKey ($ key );
85+ $ newKeys [] = $ key ;
8386 }
84- $ mgetResult = ImiRedis::use (static fn (\Imi \Redis \RedisHandler $ redis ) => $ redis ->mget ($ keys ), $ this ->poolName , true );
87+ $ mgetResult = ImiRedis::use (static fn (\Imi \Redis \RedisHandler $ redis ) => $ redis ->mget ($ parsedKeys ), $ this ->poolName , true );
8588 $ result = [];
8689 if ($ mgetResult )
8790 {
8891 foreach ($ mgetResult as $ i => $ v )
8992 {
9093 if (false === $ v )
9194 {
92- $ result [$ keys [$ i ]] = $ default ;
95+ $ result [$ newKeys [$ i ]] = $ default ;
9396 }
9497 else
9598 {
96- $ result [$ keys [$ i ]] = $ this ->decode ($ v );
99+ $ result [$ newKeys [$ i ]] = $ this ->decode ($ v );
97100 }
98101 }
99102 }
@@ -114,21 +117,22 @@ public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null
114117 {
115118 $ setValues = $ values ;
116119 }
120+ $ values = [];
117121 foreach ($ setValues as $ k => $ v )
118122 {
119- $ setValues [$ this ->parseKey ((string ) $ k )] = $ this ->encode ($ v );
123+ $ values [$ this ->parseKey ((string ) $ k )] = $ this ->encode ($ v );
120124 }
121125 // ttl 支持 \DateInterval 格式
122126 if ($ ttl instanceof \DateInterval)
123127 {
124128 $ ttl = DateTime::getSecondsByInterval ($ ttl );
125129 }
126- $ result = ImiRedis::use (static function (\Imi \Redis \RedisHandler $ redis ) use ($ setValues , $ ttl ) {
130+ $ result = ImiRedis::use (static function (\Imi \Redis \RedisHandler $ redis ) use ($ values , $ ttl ) {
127131 $ redis ->multi ();
128- $ redis ->mset ($ setValues );
132+ $ redis ->mset ($ values );
129133 if (null !== $ ttl )
130134 {
131- foreach ($ setValues as $ k => $ v )
135+ foreach ($ values as $ k => $ v )
132136 {
133137 $ redis ->expire ((string ) $ k , $ ttl );
134138 }
0 commit comments