0

We are currently using Redis as our data store. I am making a new section where we need to rank and paginate users. So i am thinking to use Sorted set for keeping rank and userid. And Hash for keeping user's profile data. It was brought to my attention by a colleague that we ll need to make many requests to redis to fetch users profile data using HGET. so Round trip time is going to be an issue. I was planning to use HMGET but After doing some research i found it may cause issues when Redis is clustered because Keys are stored in different redis nodes. I am using phpredis it has client side-sharding (I am having trouble understanding what that is).

i was thinking to do like this:

rank

zadd userRank 1 5 zadd userRank 2 2 zadd userRank 3 4 zadd userRank 4 3 

userProfile

hset userProfile user:5 "{'userId':'5','name':'usera'}" hset userProfile user:4 "{'userId':'4','name':'userb'}" hset userProfile user:3 "{'userId':'3','name':'userc'}" hset userProfile user:2 "{'userId':'2','name':'userb'}" 

1) Will HMGET work normally in clustered Redis?

2) if not what can i do?

3) is there any better way to implement this?

2
  • What method are you using to cluster - the client-side sharding, Redis Cluster, or something else? Commented Dec 6, 2013 at 7:26
  • @ShaneMadden we are using client-side sharding Commented Dec 6, 2013 at 7:34

1 Answer 1

3
  1. HMGET should work in clustered Redis because it's only related to a single key. Each HMGET will be forwarded to the node that contains the key
  2. /
  3. It's not a good idea to store every serialized user in a hash you'll loose the ability to request/inc/dec some fiels.

Prefer:

hmset user:5 userId 5 name usera hmset user:4 userId 4 name userb hmset user:3 userId 3 name userc hmset user:2 userId 2 name userb 

Your ranking schema is ok. To retrieve & paginate between the top ranked users, just do a ZREVRANGEBYSCORE and then request each users.

Note: clustering is not the same as sharding.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.