Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
Cómo buscar claves recursivamente en nodejs redis

De acuerdo con las soluciones propuestas aquí , escribí esta función para escanear claves recursivamente en NodeJS Redis - node-redis para un patrón dado:

 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

Anteriormente inserté una clave con una test: + alguna cadena, pero buscando

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

que tendrá como valores iniciales cursor = '0' y returnSet = new Set() , no parece encontrar nada, lo que resulta en un resultSet de resultados vacío y no alcanza la condición de salida del cursor 0 . ¿Por qué?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!