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

191
Views
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 answers
Answer question

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 Report
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!