@@ -416,13 +416,16 @@ export default class RedisCluster<
416416 fn : ( client : RedisClientType < M , F , S , RESP , TYPE_MAPPING > , opts ?: ClusterCommandOptions ) => Promise < T >
417417 ) : Promise < T > {
418418 const maxCommandRedirections = this . _options . maxCommandRedirections ?? 16 ;
419- let client = await this . _slots . getClient ( firstKey , isReadonly ) ;
419+ let { client, slotNumber } = await this . _slots . getClientAndSlotNumber ( firstKey , isReadonly ) ;
420420 let i = 0 ;
421421
422422 let myFn = fn ;
423423
424424 while ( true ) {
425425 try {
426+ if ( options !== undefined ) {
427+ options . slotNumber = slotNumber ;
428+ }
426429 return await myFn ( client , options ) ;
427430 } catch ( err ) {
428431 myFn = fn ;
@@ -451,7 +454,9 @@ export default class RedisCluster<
451454
452455 if ( err . message . startsWith ( 'MOVED' ) ) {
453456 await this . _slots . rediscover ( client ) ;
454- client = await this . _slots . getClient ( firstKey , isReadonly ) ;
457+ const clientAndSlot = await this . _slots . getClientAndSlotNumber ( firstKey , isReadonly ) ;
458+ client = clientAndSlot . client ;
459+ slotNumber = clientAndSlot . slotNumber ;
455460 continue ;
456461 }
457462
@@ -485,11 +490,11 @@ export default class RedisCluster<
485490 type Multi = new ( ...args : ConstructorParameters < typeof RedisClusterMultiCommand > ) => RedisClusterMultiCommandType < [ ] , M , F , S , RESP , TYPE_MAPPING > ;
486491 return new ( ( this as any ) . Multi as Multi ) (
487492 async ( firstKey , isReadonly , commands ) => {
488- const client = await this . _self . _slots . getClient ( firstKey , isReadonly ) ;
493+ const { client } = await this . _self . _slots . getClientAndSlotNumber ( firstKey , isReadonly ) ;
489494 return client . _executeMulti ( commands ) ;
490495 } ,
491496 async ( firstKey , isReadonly , commands ) => {
492- const client = await this . _self . _slots . getClient ( firstKey , isReadonly ) ;
497+ const { client } = await this . _self . _slots . getClientAndSlotNumber ( firstKey , isReadonly ) ;
493498 return client . _executePipeline ( commands ) ;
494499 } ,
495500 routing ,
0 commit comments