Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Efficiently query Redis

I am building a wallet app and I am using redis for caching the current wallet balance of a user. I was asked to retrieve the sum of the entire balance of all users using the application. I have been looking for a way to query redis for this data since it's already cached there.

The keys I used to save them are user_id-current-balance. Is there a way I can get all the keys ending with -current-balance and then retrieve all the data they hold? Is there a better way to do this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can get all matching keys, then sum the values of the keys in a loop. Use one of the following to obtain the keys:

  • KEYS pattern: O(N) with N being the number of keys in the database

    This is generally not a performant solution (but if your db is very small, you can test the query cost).

  • SMEMBERS key: O(N) where N is the set cardinality

    Using this technique, you'd create a set at key and then add each key holding a user balance (e.g. user_id_1-current-balance, user_id_2-current-balance, etc.).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda