Is it possible by HSCAN command, Only providing the host and port of single node, which automatically detect the cluster node and gives all data?
currently made a temporary fix by iterating through all the node.
How exactly to do it is depends on client you are using.
Generally redis use XModem CRC 16 algorithm to determine where is the key stored, check this source code: https://github.com/h0x91b/fast-redis-cluster/blob/remake/index.js#L92:L175
To know where is the key actually stored you should calculate xmodem crc16 of the key name, then take module of 16384. The result is the bucket number, now you can use CLUSTER NODES command to determine which server serve this bucket..
For example, our key name is 123456789
crc16 of 123456789 is 12739
12739 % 16384 = 12739, so our bucket is 12739
Then run CLUSTER NODES command, not matter on which master\slave server.
You will see something like this:
2339fe27bd311835712965a764839b4acaf41d5c 127.0.0.1:7012@17012 slave b43c92c05670537a60bcbf5430fef5e66ddebbcf 0 1493302253929 4 connected
f3007f3c2bc3a2826a3ed8e54a5e651e7457161a 127.0.0.1:7001@17001 myself,master - 0 0 0 connected 0-8191
1a054a84924109d277133bc1c14b0266f21b9f29 127.0.0.1:7003@17003 master - 0 1493302250907 3 connected 16383
577877f65e2c57a60849f242a2e740e822642431 127.0.0.1:7011@17011 slave f3007f3c2bc3a2826a3ed8e54a5e651e7457161a 0 1493302254932 1 connected
b43c92c05670537a60bcbf5430fef5e66ddebbcf 127.0.0.1:7002@17002 master - 0 1493302249900 1 connected 8192-16382
47bf2c2f5e2e6acf10dff8568f8212a014335a5c 127.0.0.1:7013@17013 slave 1a054a84924109d277133bc1c14b0266f21b9f29 0 1493302252924 3 connected
Each line is a server. 2339fe27bd311835712965a764839b4acaf41d5c is id of the server, then ip address and port, flags and settings.
We need to find the line which contain flag master and on the end of this line you will see what buckets this server are hosting.
In my case needed line is:
b43c92c05670537a60bcbf5430fef5e66ddebbcf 127.0.0.1:7002@17002 master - 0 1493302249900 1 connected 8192-16382
8192-16382 <<< this server serve buckets 8192,8193,8194...16382 (inclusively) so our key located on server 127.0.0.1:7002
There are only two syntaxes for buckets.
One more thing, redis supports Hashtags in cluster mode, if the key looks like hello{world} crc16 we do only on 'hello' without '{world}' crc16('hello') this can help you to store the keys on same instance..
Combination of node-redis and node-redis-streamify gives me the result as I expected...
var redis = require("redis");
require('node-redis-streamify')(redis);
// Host and port of single node
var client = redis.createClient({host:xyz, port:xyz});
var pattern = '*', count = 1000, hscan = client.streamified('HSCAN');
hscan(key, pattern, count)
.on('data', function (data) {
console.log('hscan data ***', data);
})
.on('error', function (error) {
console.log('hscan error ***', error);
})
.on('end', function () {
console.log('hscan end ***');
});