Skip to content

Struggling To Understand Multi Command Typing In V5 #2953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AdrianMcGrathFlailsoft opened this issue May 8, 2025 · 0 comments
Open

Struggling To Understand Multi Command Typing In V5 #2953

AdrianMcGrathFlailsoft opened this issue May 8, 2025 · 0 comments
Assignees

Comments

@AdrianMcGrathFlailsoft
Copy link

Description

I am attempting to figure out how to properly type the multi command in the v5 version of this package, and I could use some assistance.

Here is an example of something I had in the v4 version:

let multi = client.multi().mSet(mSetRequest);
for (const request of requests) {
    multi = multi.pExpire(request.key, expiration);
}

const results = await multi.exec<"typed">();
return results.every((res) => res === 1 || res === "OK");

I am getting two separate typescript errors here. I understand what they are saying, but I don't understand how to resolve them.

Based on my understanding, the first line creates a RedisClientMultiCommandType where the REPLIES generic is ["OK"], because that is the valid response from the mSet command. When I am in the loop and I attempt to add the pExpire() command to the multi, I get a typescript error complaining that I cannot add pExpire because pExpire returns a number, which is not an allowed value for the REPLIES generic. For that same reason, when I attempt to resolve things in the final line, the "res === 1" part has a typescript error because, once again, a number is not a valid thing for REPLIES.

If that REPLIES generic automatically gets hard set to whatever commands are used ONLY during the initial creation of the RedisClientMultiCommandType, how are we supposed to add commands to the multi?

I tried typing the REPLIES manually during creation:

let multi: RedisClientMultiCommandType<["OK", number], any, any, any, any, any> = client.multi().mSet(mSetRequest);

But that just leads to the error: "Type ["OK"] is not assignable to type ReplyUnion[] | ["OK", number]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants