I am using this
redisManager.redisClient.keys('*example*', function (err, keys) {
})
But it only gives keys from only one of the redis cluster. How can I get keys from all cluster?
I am using this
redisManager.redisClient.keys('*example*', function (err, keys) {
})
But it only gives keys from only one of the redis cluster. How can I get keys from all cluster?
Keys command not recommended to be used in productions mode.
From redis docs Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.
Use scanStream Instead
redisConnection = redisConnectionObject;
const slaves = redisConnection.nodes("slave");
config.info('number of slaves', slaves.length)
let keys = [];
let slavePromises = [];
slaves.forEach((slave) => {
let slaveCreate = new Promise((resolve) => {
const stream = slave.scanStream({
match: prefix
});
stream.on("data", (resultKeys) => {
keys = [...keys, ...resultKeys];
});
stream.on("end", () => {
resolve();
});
});
slavePromises.push(slaveCreate);
});
Promise.all(slavePromises).then(([slaveOneData, slaveTwoData]) => {
keys = _.uniq(keys);
resolveOne(keys);
});