Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
What method are you using to cluster - the client-side sharding, Redis Cluster, or something else? –  Shane Madden Dec 6 '13 at 7:26
    
@ShaneMadden we are using client-side sharding –  Jay Dec 6 '13 at 7:34

1 Answer 1

up vote 1 down vote accepted
  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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.