Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get a member with maximum (or minimum ) score from redis sorted set given a subset of members?

I am writing a algo for deducing the user with the least amount of work load. Based on the type/complexity of the tasks being created, i narrow down on the list of the users that are capable of performing it. Now, I need to find the user who has the least number tasks currently assigned to him/her. I am using redis sorted set to store the members/users along the score indicating the number of the tasks assigned to them. Is there a way to get a member with least score given a subset of members?

like image 899
KCore Avatar asked Nov 16 '13 10:11

KCore


1 Answers

Member with minimum score:

ZRANGEBYSCORE myset -inf +inf WITHSCORES LIMIT 0 1

Member with maximum score:

ZREVRANGEBYSCORE myset +inf -inf WITHSCORES LIMIT 0 1
like image 181
Mirek Rusin Avatar answered Nov 08 '22 12:11

Mirek Rusin