-
Notifications
You must be signed in to change notification settings - Fork 23.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SORT sortedset BY score #98
Comments
use ZRANGEBYSCORE or ZREVRANGEBYSCORE instead. |
I should have been more explicit. How about this:
|
hmmm, you want something like this?
"BY score" is not needed here, "SORT sortedset" is enough, and i use "SORT s ALPHA" because sorted set 's' is stored string value. |
Hello, I'm usually not very inclined about making changes to SORT, it's at its maximum level of complexity already IMHO, and the scripting support in 2.6 will make it easy to do fancy stuff server side. But... I must agree that "SORT sortedset BY nosort" should return elements ordered by score as it is the least surprise behavior for sure, and is probably also faster since the sorted set is a linked list. So I'm accepting this feature as: "make sure that when no sorting is performed by SORT, elements in a sorted set are returned in the obvious order, that is, by score". Thanks for reporting. |
Hi huangz1990, I already knew that you can do that (see my original question "without extra keys"). It's rather nasty to duplicate the scores to extra keys when you already have the scores in sorted set. antirez, Your suggestion is fine as with this "nosort" behavior we have the same functionality as with for example: ASC Sorting sorted set (i.e.
DESC Sorting sorted set (i.e.
|
this would be nice to have. I'm currently making an zrevrange to get the elements ordered, storing them in a list and then doing the sort to retrieve a list of hashes. With this I could skip that extra step. |
Any update on this? We were caught by it recently. Currently we have to maintain another extra_list just to store the score just for sorting:
With this implemented we can get rid of that extra_list |
windix: I just tried
and it works for me, in 2.6. |
Hi Klodio, I tried on the latest version 2.6.0-RC5 and it doesn't work for me. I guess it treats the "score" as an non-existing key, so sorting is simply skipped. See "Skip sorting the elements" in http://redis.io/commands/sort Correct me if i am wrong, thanks :) |
You're right, |
I'd also appreciate this feature. |
Any update on this. It would tremendously help in my case, instead of having to keep track of another set of keys just for sorting. |
Any updates to this? It was posted and approved about a year ago, but it's still unresolved. Antirez even said that it could increase the performance. This sounds trivial to fix. Am I wrong? |
We neeeeeed this feature too) |
Note: make sure that ASC/DESC will do what makes sense in this context. |
Hi Antirez, Are u indicating that this feature already exists? |
When SORT is called with the option BY set to a string constant not inclduing the wildcard character "*", there is no way to sort the output so any ordering is valid. This allows the SORT internals to optimize its work and don't really sort the output at all. However it was odd that this option was not able to retain the natural order of a sorted set. This feature was requested by users multiple times as sometimes to call SORT with GET against sorted sets as a way to mass-fetch objects can be handy. This commit introduces two things: 1) The ability of SORT to return sorted sets elements in their natural ordering when `BY nosort` is specified, accordingly to `DESC / ASC` options. 2) The ability of SORT to optimize this case further if LIMIT is passed as well, avoiding to really fetch the whole sorted set, but directly obtaining the specified range. Because in this case the sorting is always deterministic, no post-sorting activity is performed when SORT is called from a Lua script. This commit fixes issue #98.
When SORT is called with the option BY set to a string constant not inclduing the wildcard character "*", there is no way to sort the output so any ordering is valid. This allows the SORT internals to optimize its work and don't really sort the output at all. However it was odd that this option was not able to retain the natural order of a sorted set. This feature was requested by users multiple times as sometimes to call SORT with GET against sorted sets as a way to mass-fetch objects can be handy. This commit introduces two things: 1) The ability of SORT to return sorted sets elements in their natural ordering when `BY nosort` is specified, accordingly to `DESC / ASC` options. 2) The ability of SORT to optimize this case further if LIMIT is passed as well, avoiding to really fetch the whole sorted set, but directly obtaining the specified range. Because in this case the sorting is always deterministic, no post-sorting activity is performed when SORT is called from a Lua script. This commit fixes issue #98.
Fixed & merged into 2.6. Closing, thanks for your help. |
Does this mean that this...
has the same complexity as:
|
Does anyone knows the answer to the last question? |
I just found out that executing this:
Actually doesn't return the values in the order they are in sorted set. Could we extend SORT command to support this:
Or is there another way to archive this without extra keys?
The text was updated successfully, but these errors were encountered: