Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:59:38+00:00 2026-06-02T12:59:38+00:00

Assume we have a simple mysql table(user) with fields: id rating salary I want

  • 0

Assume we have a simple mysql table(user) with fields:

id
rating
salary

I want to get 10 users with highest rating and salary with specified range(50-100), i.e in mysql it would be

SELECT id from user WHERE salary>50 and salary<100 ORDER by rating limit 0, 10

This runs for 20ms on 100K users table.

Assume I have same in redis:
Zlist rating (rating=>user_id)
Zlist salary (salary=>user_id)

All solutions I saw with redis include copying 100k salary Zlist, removing unneeded entries, and merging with 100k rating list, like

zinterstore 1 search salary
zremrange search -inf 50
zremrange search 100 +inf
zinterstore 2 search rating weights 0 1
zrange search 0 10

which is absolutely slow(why copy 100k elements to remove most of them?).

Is there any way to implement this at least comparably efficient with redis?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:59:39+00:00Added an answer on June 2, 2026 at 12:59 pm

    The use case you describe cannot be modeled elegantly in NoSQL solutions. It isn’t a Redis limitation.

    Let me explain that a bit more. You are running range queries on one field, and sorting on another. This isn’t something NoSQL solutions are good at. For example, Google App Engine forbids such queries. Take a look at GAE Query Restrictions and read the section “Properties in Inequality Filters Must Be Sorted before Other Sort Orders”

    To get all results that match an inequality filter, a query scans the
    index table for the first matching row, then returns all consecutive
    results until it finds a row that doesn’t match. For the consecutive
    rows to represent the complete result set, the rows must be ordered by
    the inequality filter before other sort orders.

    Having said that, you can still efficiently run your queries, but the solution isn’t going to be elegant.

    1. Create salary ranges – 0-5000, 5000-10000, 10000-15000 and so on
    2. Create sets like users_with_salary:10000-15000. This set will contain user ids who have salary in the given range.
    3. Similarly, create sets like `users_with_rating:1-2″. This set will contain user ids who have ratings in the given range
    4. Now, run the following pseudo code
    
    String userids[];
    for(rating = 10; rating > 0; rating--) {
      for(salary = min_salary; salary < max_salary; salary += 5000) {
          String salary_key = "users_with_salary:" + salary + "-" + (salary+5000);
          String rating_key = "users_with_rating:" + rating + "-" + (rating+1);
    
          userids.append(redis.sinter(salary_key, rating_key));
    
          if(userids.length > 10) {
             break;
          }
       }
    }
    
    

    With redis 2.6 and lua scripting, you can even run this on the lua server.

    In conclusion, if you want to run complex queries on your data, it is best to model it in a relational database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the simple case, assume I have a table that looks like this: mysql>
Assume I have an enumerable object enum and now I want to get the
So I want to do the simplest possible thing. Assume I have a MYSQL
Let's assume we have this very simple table: |class |student| --------------- Math Alice Math
Let's assume we have this very simple 'test' table. There is: 5 bob, 2
Let's assume we have a simple internet socket, and it's going to send 10
I have a MySQL table which basically serves as a file index. The primary
Let's say I have a MySQL database with 3 tables: table 1: Persons, with
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
I am trying to setup a simple database in which I have a user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.