Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c50693d4
Commit
c50693d4
authored
Dec 11, 2014
by
Salvatore Sanfilippo
Browse files
Merge pull request #2094 from mattsta/nosort
Fix zero-ordering SORT when called against lists
parents
81772ce0
6c0abc4a
Changes
2
Show whitespace changes
Inline
Side-by-side
src/sort.c
View file @
c50693d4
...
@@ -285,16 +285,13 @@ void sortCommand(redisClient *c) {
...
@@ -285,16 +285,13 @@ void sortCommand(redisClient *c) {
return
;
return
;
}
}
/* For the STORE option, or when SORT is called from a Lua script,
/* When sorting a set with no sort specified, we must sort the output
* we want to force a specific ordering even when no explicit ordering
* so the result is consistent across scripting and replication.
* was asked (SORT BY nosort). This guarantees that replication / AOF
* is deterministic.
*
*
* However in the case 'dontsort' is true, but the type to sort is a
* The other types (list, sorted set) will retain their native order
* sorted set, we don't need to do anything as ordering is guaranteed
* even if no sort order is requested, so they remain stable across
* in this special case. */
* scripting and replication. */
if
((
storekey
||
c
->
flags
&
REDIS_LUA_CLIENT
)
&&
if
((
dontsort
&&
sortval
->
type
==
REDIS_SET
))
(
dontsort
&&
sortval
->
type
!=
REDIS_ZSET
))
{
{
/* Force ALPHA sorting */
/* Force ALPHA sorting */
dontsort
=
0
;
dontsort
=
0
;
...
...
tests/unit/sort.tcl
View file @
c50693d4
...
@@ -246,6 +246,24 @@ start_server {
...
@@ -246,6 +246,24 @@ start_server {
r sort mylist by num get x:*->
r sort mylist by num get x:*->
}
{
100
}
}
{
100
}
test
"SORT by nosort retains native order for lists"
{
r del testa
r lpush testa 2 1 4 3 5
r sort testa by nosort
}
{
5 3 4 1 2
}
test
"SORT by nosort plus store retains native order for lists"
{
r del testa
r lpush testa 2 1 4 3 5
r sort testa by nosort store testb
r lrange testb 0 -1
}
{
5 3 4 1 2
}
test
"SORT by nosort with limit returns based on original list order"
{
r sort testa by nosort limit 0 3 store testb
r lrange testb 0 -1
}
{
5 3 4
}
tags
{
"slow"
}
{
tags
{
"slow"
}
{
set num 100
set num 100
set res
[
create_random_dataset $num lpush
]
set res
[
create_random_dataset $num lpush
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment