Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
In redis cluster how to get the data of whole cluster which is set by command HMSET by node redis client?

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.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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.

  1. 1-125 - from 1 to 125
  2. 1,3,5 - bucket 1 and 3 and 5
  3. 1-10,15,18,20-100 - just mix of two above

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..

over 4 years ago · Santiago Trujillo Relatório

0

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 ***');
     });
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda