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

278
Views
Get a keys matching pattern from Redis cache - node-redis

I am trying to cache a paginated API call. To fetch the data from Mongo DB using EXPRESS API.

Currently I am storing a page wise data in cache, with key structure mentioned below,

Key :1 
 {
   model: 'bookmarks',
   userId: '609bf4a1e9df4334acb2da7a',
   collection: '0',
   page: '1'
 }
Key 2
 {
   model: 'bookmarks',
   userId: '609bf4a1e9df4334acb2da7a',
   collection: '0',
   page: '2'
 }

and so on.

My use case is , if user has made an update to data fetched for particular collection example (0) , I intend to delete all the keys w.r.t. the collection present in the Redis client.

So far I have been able to get all the keys using 'keys *', I can filter and delete data from here, but as recommended in docs it's not recommended for production.

    redisClient.keys('*', function (err, keys) {
      if (err) return console.log(err);
      console.log('keys', keys);
      let newArray = [];
      console.log('keys', newArray);
      keys.forEach(function (key) {
        newArray.push(JSON.parse( key));
      });
      console.log('keys', newArray);
})

I am new to node-redis. Need help to understand the commands to get the key matching a pattern {model:'bookmarks',collection:'0',userId:'1234:'} so that I can clear cache for all the occurrences.

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!