One can select only one member at a time from sorted set ZSCORE key member.
However, other commands allow to operate on multiple members. For example, the delete command: ZREM key member [member ...].
Analogous as ZREM command the ZSCORE command should allow to select multiple member in one request, like: ZSCORE key member [member ...].
Comment From: itamarhaber
@streamich Unless there's a really compelling reason, I don't see this
happening for the following reasons:
1. Changing ZSCORE to a variadic command will require changing its
response type, this breaking the existing API.
2. Adding a new command to Redis, e.g. MZSCORE, is also problematic
because we already have 160+ of these and no wish to grow for every
variation.
In such cases, the current recommendation is to use Lua scripting to close the gap - untested example:
local r = {} for _, k in pairs(ARGV) do r[#r+1] = redis.call("ZSCORE", KEYS[1], k) end
return r On Feb 2, 2015 2:52 AM, "streamich" notifications@github.com wrote:
One can select only one member at a time from sorted set ZSCORE key member .
However, other commands allow to operate on multiple members. For example, the delete command: ZREM key member [member ...].
Analogous as ZREM command the ZSCORE command should allow to select multiple member in one request, like: ZSCORE key member [member ...].
— Reply to this email directly or view it on GitHub https://github.com/antirez/redis/issues/2344.
Comment From: antirez
While I share @itamarhaber reasoning on a general line, MZSCORE may have its place because it is extremely generally useful as an operation. Everybody using sorted sets as both a key -> number map, and as a side effect as an ordered map, is going to need an MGET alike operation in the sorted set seen in the POV of an hash. Let me thing a bit about it... maybe there are other good alternative solutions API-wise, otherwise this may be the best.
Comment From: streamich
Maybe you could add MZSCORE in the current major release, as it is indeed very much needed command, much more than ZREM key member [member ...]. Then in the next major release MZSCORE would become ZSCORE, or ZSCORE would become deprecated, if you think you have too many commands.
Comment From: Marak
MZSCORE seems like it would be a useful method.
We currently have to do this in the application layer with multiple ZSCORE requests to redis.
If anyone is interested I found a module which appears to achieve mzscore: http://redismodules.com/commands/mzscore/
Comment From: Ivoruhs
Hello, this is a very good thread. Does MZSCORE return bulk reply in sorted manner? This is very much needed for that keeps up with the usage of sorted set I guess.
Comment From: dhensen
3 year later and I am running into this exact issue. What is the currently best solution to get this wanted behaviour? Module, lua or loop over ZSCORE in my own program?
Comment From: itamarhaber
I'd go with Lua - the module mentioned above isn't maintained ATM, and I'd be surprised if it even compiles (disclaimer: author here). You could of course write your own module, but personally I don't think it is worth the trouble as a simple Lua script will perform (almost) just as well. I really recommend against looping in your code though, although I'd be less harsh about it if you pipeline the requests.
Comment From: oranagra
merged https://github.com/redis/redis/pull/7593, closing.
Comment From: zii
How about GEOMDIST?
Comment From: itamarhaber
@zii aye, I have it somewhere in my lists, but feel free to open a feature request to initiate the discussion.