Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

304
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda