I hope I understand the structure of your sorted set:
members/users => score
So, you have several ways to resolve your issue. But there is no solution to do this on a single redis team.
Get data with a set of ZSCORE calls. PHP with phpredis lib sample with O (N) complexity.
$subsetOfUsers = ['user1', 'user2']; $multi = $redis->multi(); foreach ($subsetOfUsers as $user) { $redis->zScore('yourKey', $user); } $result = $multi->exec();
Using ZINTERSTORE . Add a subset of the participants to the sorted into the tempera set with ZADD and ZINTERSTORE temp sorted set with your sorted set. Then get the results with ZRANGE . This can be done using MULTI .
ADD tmp 0 "user1" ADD tmp 0 "user2" ZINTERSTORE out 2 tmp yourDataSortedSetKey ZRANGE out 0 -1 WITHSCORES
This is a clear "redis path" with algorithmic complexity O (N * K) + O (M * log (M)).
ps If you are using redis> = 2.6, you can write a LUA stored procedure to optimize both given patterns.
source share