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
237194b7
Commit
237194b7
authored
Dec 01, 2011
by
antirez
Browse files
Fixed SORT bugs (issue #224) with regression tests.
parent
1576520c
Changes
2
Show whitespace changes
Inline
Side-by-side
src/sort.c
View file @
237194b7
...
@@ -141,11 +141,7 @@ void sortCommand(redisClient *c) {
...
@@ -141,11 +141,7 @@ void sortCommand(redisClient *c) {
/* Lookup the key to sort. It must be of the right types */
/* Lookup the key to sort. It must be of the right types */
sortval
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
1
]);
sortval
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
1
]);
if
(
sortval
==
NULL
)
{
if
(
sortval
&&
sortval
->
type
!=
REDIS_SET
&&
sortval
->
type
!=
REDIS_LIST
&&
addReply
(
c
,
shared
.
emptymultibulk
);
return
;
}
if
(
sortval
->
type
!=
REDIS_SET
&&
sortval
->
type
!=
REDIS_LIST
&&
sortval
->
type
!=
REDIS_ZSET
)
sortval
->
type
!=
REDIS_ZSET
)
{
{
addReply
(
c
,
shared
.
wrongtypeerr
);
addReply
(
c
,
shared
.
wrongtypeerr
);
...
@@ -161,7 +157,10 @@ void sortCommand(redisClient *c) {
...
@@ -161,7 +157,10 @@ void sortCommand(redisClient *c) {
/* Now we need to protect sortval incrementing its count, in the future
/* Now we need to protect sortval incrementing its count, in the future
* SORT may have options able to overwrite/delete keys during the sorting
* SORT may have options able to overwrite/delete keys during the sorting
* and the sorted key itself may get destroied */
* and the sorted key itself may get destroied */
if
(
sortval
)
incrRefCount
(
sortval
);
incrRefCount
(
sortval
);
else
sortval
=
createListObject
();
/* The SORT command has an SQL-alike syntax, parse it */
/* The SORT command has an SQL-alike syntax, parse it */
while
(
j
<
c
->
argc
)
{
while
(
j
<
c
->
argc
)
{
...
@@ -200,7 +199,8 @@ void sortCommand(redisClient *c) {
...
@@ -200,7 +199,8 @@ void sortCommand(redisClient *c) {
}
}
/* Destructively convert encoded sorted sets for SORT. */
/* Destructively convert encoded sorted sets for SORT. */
if
(
sortval
->
type
==
REDIS_ZSET
)
zsetConvert
(
sortval
,
REDIS_ENCODING_SKIPLIST
);
if
(
sortval
->
type
==
REDIS_ZSET
)
zsetConvert
(
sortval
,
REDIS_ENCODING_SKIPLIST
);
/* Load the sorting vector with all the objects to sort */
/* Load the sorting vector with all the objects to sort */
switch
(
sortval
->
type
)
{
switch
(
sortval
->
type
)
{
...
@@ -367,12 +367,9 @@ void sortCommand(redisClient *c) {
...
@@ -367,12 +367,9 @@ void sortCommand(redisClient *c) {
}
}
}
}
}
}
setKey
(
c
->
db
,
storekey
,
sobj
);
if
(
outputlen
)
setKey
(
c
->
db
,
storekey
,
sobj
);
decrRefCount
(
sobj
);
decrRefCount
(
sobj
);
/* Note: we add 1 because the DB is dirty anyway since even if the
server
.
dirty
+=
outputlen
;
* SORT result is empty a new key is set and maybe the old content
* replaced. */
server
.
dirty
+=
1
+
outputlen
;
addReplyLongLong
(
c
,
outputlen
);
addReplyLongLong
(
c
,
outputlen
);
}
}
...
...
tests/unit/sort.tcl
View file @
237194b7
...
@@ -134,6 +134,18 @@ start_server {
...
@@ -134,6 +134,18 @@ start_server {
assert_equal
[
lsort -real $floats
]
[
r sort mylist
]
assert_equal
[
lsort -real $floats
]
[
r sort mylist
]
}
}
test
"SORT with STORE returns zero if result is empty (github isse 224)"
{
r flushdb
r sort foo store bar
}
{
0
}
test
"SORT with STORE does not create empty lists (github issue 224)"
{
r flushdb
r lpush foo bar
r sort foo limit 10 10 store zap
r exists zap
}
{
0
}
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