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

301
Views
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
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!