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 to flushAll while using a createCluster instance #2446

Open
egmzy opened this issue Mar 19, 2023 · 1 comment
Open

How to flushAll while using a createCluster instance #2446

egmzy opened this issue Mar 19, 2023 · 1 comment
Assignees

Comments

@egmzy
Copy link

egmzy commented Mar 19, 2023

Description

I'm using createCluster as a client instance to run commands like GET and SET.

const client: RedisClusterType = createCluster(options)

I want to implement a deleteAllKeys function but RedisClusterType doesn't have FLUSHALL.

async deleteAllKeys() {
    return await client.FLUSHALL();
}

The only Info I could find is here in the docs:
https://github.com/redis/node-redis/blob/HEAD/docs/clustering.md

It mentions getSlotMaster() but no explanation on how to use it.
Also the code says it's deprecated and we should use slots() instead, which I couldn't find docs for.

Any idea on how I can approach this?

@leibale
Copy link
Contributor

leibale commented Mar 19, 2023

Until #2431 will be implemented, you can use this to run FLUSHALL on all masters:

await Promise.all(
  cluster.masters.map(async master => {
    await (await cluster.nodeClient(master)).flushAll();
  });
);

client.slots - if you want to get the client of a specific slot
client.shards - if you want to work on a "per shard" (master + it's replicas) basis.
client.masters - just the masters
client.replicas - just the replicas

we definitely need to update the docs..

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

Successfully merging a pull request may close this issue.

2 participants