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 5947935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:02:08+00:00 2026-05-22T17:02:08+00:00

I have users as Redis Hashes and want to find similar users (given a

  • 0

I have users as Redis Hashes and want to find similar users (given a particular user) based on salary and age.

<user>
  <id>101</id>
  <name>Neo</name>
  <age>30</age>
  <salary>300</salary>
  ....
</user>

So, in this case I need to find users who are close to my age AND salary close to my salary both within some given limits.
In SQL, I would hypothetically do something like

SELECT id, abs(age - 30) as agediff, abs(salary - 300) as saldiff FROM
 USERS WHERE 
(age BETWEEN 25 35) AND (salary BETWEEN 250 350) ORDER BY agediff ASC, saldiff ASC

Can we do this, say using ZINTERSTORE, in such a way that the resulting set is ordered by user similarity like in the SQL?

  • 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-05-22T17:02:09+00:00Added an answer on May 22, 2026 at 5:02 pm

    This is not exactly as easy as a SQL query. You need set some keys etc.

    Nevertheless here is what I think is the way to do it.
    You would need to create two sorted sets with user id as member and age/salary as score.

    ZADD index:user:age 30 101 # 101 is id of user whose name is Neo
    ZADD index:user:salary 300 101 
    

    Create intermediate sets for both conditions

    # Condition 1: age 25-30
    ZUNIONSTORE temp:age 1 index:user:age WEIGHTS 1
    ZREMRANGEBYSCORE temp:age 0 24
    ZREMRANGEBYSCORE temp:age 36 INF
    # Condition 2: Repeat above for salary
    # Now create result set which is intersection of both above sets
    ZINTERSTORE temp:result 2 temp:salary temp:age # 2 is no. of sets to intersect
    # Verify result
    ZRANGE temp:result 0 -1
    

    Finally

    • remove temp keys
    • Run all these commands using MULTI/EXEC so that there is only one round trip
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have a simple mysql table(user) with fields: id rating salary I want
I have users table and want to SELECT some rows by bitmask criteria. I'll
i have users table and i have posts table i want select from users
In my web application I will have users, each user will have albums, and
I have a simple array of hashes retrieved from Redis in my Ruby on
I have a whole bunch of fields for each user in my redis database,
I have many products (product_id). Users (user_id) view the products. I want to query
If I have multiple users who publish to a channel via redis how does
I have a website from where I want users to link their GMail account,
I have an app (for a given twitter user) that gets a list of

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.