Skip to content
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

How auto-pipelining works? #2836

Open
MARCROCK22 opened this issue Sep 18, 2024 · 1 comment
Open

How auto-pipelining works? #2836

MARCROCK22 opened this issue Sep 18, 2024 · 1 comment

Comments

@MARCROCK22
Copy link

Description

how can I check if something is being executed as a pipeline?
I know that docs says this code is automatically handled as a pipeline because they are in the same "tick":

await Promise.all([
   client.set(...),
   client.set(...),
   client.set(...),
])

but

const promises: Promise<unknown>[] = [];

for (const [key, value] of data) {
    promises.push(client.hSet(key, value));
    promises.push(client.expire(key, ...));
}

await Promise.all(promises);

is this being executed as a pipeline?

@leibale
Copy link
Collaborator

leibale commented Sep 19, 2024

Yes, both of them are pipelined as both of them are running all the commands on the same "event loop tick"

edit: you can also use

const multi = client.mulit();
for (let i = 0; i < 10; i++) {
  multi.get(i.toString());
}
const results = await multi.execAsPipeline();

In case you are executing the commands once - an array of promises + Promies.all (or similar) is the most performant way as you don't create unnecessary objects/memory. If you are executing the same commands multiple times multi would perform better as the commands will be encoded once and reused for every executing.

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