Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
a5eb649b
Commit
a5eb649b
authored
Nov 29, 2009
by
antirez
Browse files
SORT support for sorted sets
parent
80181f78
Changes
1
Show whitespace changes
Inline
Side-by-side
redis.c
View file @
a5eb649b
...
...
@@ -4805,7 +4805,9 @@ static void sortCommand(redisClient *c) {
addReply
(
c
,
shared
.
nokeyerr
);
return
;
}
if
(
sortval
->
type
!=
REDIS_SET
&&
sortval
->
type
!=
REDIS_LIST
)
{
if
(
sortval
->
type
!=
REDIS_SET
&&
sortval
->
type
!=
REDIS_LIST
&&
sortval
->
type
!=
REDIS_ZSET
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
;
}
...
...
@@ -4858,11 +4860,15 @@ static void sortCommand(redisClient *c) {
}
/* Load the sorting vector with all the objects to sort */
vectorlen
=
(
sortval
->
type
==
REDIS_LIST
)
?
listLength
((
list
*
)
sortval
->
ptr
)
:
dictSize
((
dict
*
)
sortval
->
ptr
);
switch
(
sortval
->
type
)
{
case
REDIS_LIST
:
vectorlen
=
listLength
((
list
*
)
sortval
->
ptr
);
break
;
case
REDIS_SET
:
vectorlen
=
dictSize
((
dict
*
)
sortval
->
ptr
);
break
;
case
REDIS_ZSET
:
vectorlen
=
dictSize
(((
zset
*
)
sortval
->
ptr
)
->
dict
);
break
;
default:
vectorlen
=
0
;
assert
(
0
);
/* Avoid GCC warning */
}
vector
=
zmalloc
(
sizeof
(
redisSortObject
)
*
vectorlen
);
j
=
0
;
if
(
sortval
->
type
==
REDIS_LIST
)
{
list
*
list
=
sortval
->
ptr
;
listNode
*
ln
;
...
...
@@ -4876,10 +4882,17 @@ static void sortCommand(redisClient *c) {
j
++
;
}
}
else
{
dict
*
set
=
sortval
->
ptr
;
dict
*
set
;
dictIterator
*
di
;
dictEntry
*
setele
;
if
(
sortval
->
type
==
REDIS_SET
)
{
set
=
sortval
->
ptr
;
}
else
{
zset
*
zs
=
sortval
->
ptr
;
set
=
zs
->
dict
;
}
di
=
dictGetIterator
(
set
);
while
((
setele
=
dictNext
(
di
))
!=
NULL
)
{
vector
[
j
].
obj
=
dictGetEntryKey
(
setele
);
...
...
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