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

307
Visualizações
How to scan for keys recursively in nodejs redis

According to the solutions proposed here I wrote this function to recursively scan keys in NodeJS Redis - node-redis for a given pattern:

RedisStore.prototype.scan = function(params, callback, cursor = '0', returnSet = new Set()) {
    var self = this;
    var options = {
        pattern: '',
        match: 'MATCH',
        count: 100
    };
    for (var attrname in params) {
        options[attrname] = params[attrname];
    }
    var count = '' + options.count;
    self.client.scan(cursor, options.match, options.pattern, 'COUNT', count,
        (err, reply) => {
            if (err) {
                return callback(err, null);
            }
            cursor = reply[0];
            if (cursor === '0') { // scan completed
                return callback(null, Array.from(returnSet));
            } else {
                var keys = reply[1];
                keys.forEach(function(key, i) {
                    returnSet.add(key);
                });
                return self.scan(options, callback, cursor, returnSet);
            }
        });
} // scan

I have previously inserted a key with a prefix test: + some string, but scanning for

var res = await store.scan({
    pattern: 'test:*',
    count: 10
    });

that will have as starting values cursor = '0' and returnSet = new Set(), does not seem to find anything, thus resulting in a empty resultSet and not reaching the 0 cursor exit condition. Why?

about 4 years ago · Juan Pablo Isaza
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