Skip to content
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

Support for Multiple BY patterns in SORT Command #225

Closed
wants to merge 2 commits into from

Conversation

idaunis
Copy link

@idaunis idaunis commented Dec 1, 2011

With this feature Redis will expand the applications in numerous scenarios where right now can only be performed in an SQL-like environment.

Usage
SORT key [BY pattern [ASC|DESC] [ALPHA] [BY pattern…]] [LIMIT offset count] [GET pattern [GET pattern ...]] [STORE destination]

Documentation
The BY option can be used multiple times in order to sort by multiple fields. If the list elements have the same value when ordering by the first BY pattern, then it sorts by the second BY pattern and so on.

The following example will order the list mylist by weight and by title. Sorting first the list of elements by weight, and then by title when the elements have the same weight:

SORT mylist BY weight_* BY title_* ALPHA

@BharathZoho
Copy link

This seems to be very useful, When will this feature be added to the main branch?

@Jevin23
Copy link

Jevin23 commented Dec 15, 2016

+1

@fcerbell
Copy link

It would help me a lot, too.

@gkorland
Copy link
Contributor

gkorland commented Nov 23, 2019

@idaunis can you please describe your use case?

@cscan
Copy link

cscan commented May 3, 2020

This is my test case:

127.0.0.1:6380> hmset test:01 f1 345 f2 A
127.0.0.1:6380> hmset test:02 f1 444 f2 B
127.0.0.1:6380> hmset test:03 f1 776 f2 B
127.0.0.1:6380> hmset test:04 f1 111 f2 B
127.0.0.1:6380> hmset test:05 f1 999 f2 A
127.0.0.1:6380> sadd testset test:01
127.0.0.1:6380> sadd testset test:02
127.0.0.1:6380> sadd testset test:03
127.0.0.1:6380> sadd testset test:04
127.0.0.1:6380> sadd testset test:05
127.0.0.1:6380> sort testset by *->f2 alpha by *->f1
1) "test:04"
2) "test:01"
3) "test:02"
4) "test:03"
5) "test:05"

BTW, the result should be:

1) "test:01"
2) "test:05"
3) "test:04"
4) "test:02"
5) "test:03"

+11

PatKamin added a commit to PatKamin/redis that referenced this pull request Oct 28, 2022
[6.0.8-devel] Fix make test failing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants