Skip to content

Commit 0b8bc17

Browse files
Copilothotlong
andcommitted
Fix Redis driver bulkUpdate and bulkDelete for Redis v4 client
- Fixed bulkUpdate to handle Redis v4 client pipeline results (direct values, not tuples) - Fixed bulkDelete to parse Redis v4 pipeline results correctly - Added guard to prevent executing empty pipeline in bulkUpdate - Added explanatory comments about Redis v4 client behavior Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 64c73c6 commit 0b8bc17

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/drivers/redis/src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ export class RedisDriver implements Driver, DriverInterface {
563563

564564
for (let i = 0; i < command.updates.length; i++) {
565565
const update = command.updates[i];
566-
const result = getResults?.[i] as any;
567-
const existingData = result?.[1];
566+
// Redis v4 client returns array of results directly, not [error, result] tuples
567+
const existingData = getResults?.[i];
568568

569569
if (existingData && typeof existingData === 'string') {
570570
const existingDoc = JSON.parse(existingData);
@@ -581,7 +581,10 @@ export class RedisDriver implements Driver, DriverInterface {
581581
}
582582
}
583583

584-
await setPipeline.exec();
584+
// Only execute pipeline if there are commands to execute
585+
if (updateResults.length > 0) {
586+
await setPipeline.exec();
587+
}
585588

586589
return {
587590
success: true,
@@ -602,7 +605,9 @@ export class RedisDriver implements Driver, DriverInterface {
602605
}
603606

604607
const deleteResults = await deletePipeline.exec();
605-
const deleted = deleteResults?.filter((r: any) => r && r[1] > 0).length || 0;
608+
// Redis v4 client returns array of results directly, not [error, result] tuples
609+
// Each DEL returns 1 if key existed and was deleted, 0 if key didn't exist
610+
const deleted = deleteResults?.filter((r: any) => r > 0).length || 0;
606611

607612
return {
608613
success: true,

0 commit comments

Comments
 (0)