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?
To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.
The first command you can use to get the total number of keys in a Redis database is the DBSIZE command. This simple command should return the total number of keys in a selected database as an integer value. The above example command shows that there are 203 keys in the database at index 10.
The Redis KEYS command returns all the keys in the database that match a pattern (or all the keys in the key space). Similar commands for fetching all the fields stored in a hash is HGETALL and for all fetching the members of a SMEMBERS. The keys in Redis themselves are stored in a dictionary (aka a hash table).
By clicking on a Redis key name, all its contents will open in a new editor tab. With a collection type Redis key, clicking on it will reveal the individual elements under the key name. Clicking the individual element will display its contents in a new editor tab.
You can't get keys for all nodes using a single command. You have to get keys for all nodes and merge them. Reference - https://github.com/antirez/redis/issues/1962
You can do something like.
var redis = require('redis');
redisConfig = new Array(
{"port": 1234, "host": "192.168.1.2"},
{"port": 5678, "host": "192.168.1.3"}
);
keys = new Array();
allKeys = new Array();
for(i = 0; i < redisConfig.length; i++){
redisClient = redis.createClient(redisConfig[i].port, redisConfig[i].host);
keys[i] = redisClient.keys('*example*', function (err, keys) {
allkeys = [...new Set([...allKeys ,...keys[i]])];
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With