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

280
Vistas
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
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