Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
a03611e1
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a03611e1
编写于
5月 31, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update SORT to work with the dual list encoding
上级
1cd92e7f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
31 deletion
+34
-31
redis.c
redis.c
+34
-31
未找到文件。
redis.c
浏览文件 @
a03611e1
...
...
@@ -7210,7 +7210,7 @@ static int sortCompare(const void *s1, const void *s2) {
* is optimized for speed and a bit less for readability */
static
void
sortCommand
(
redisClient
*
c
)
{
list
*
operations
;
int
outputlen
=
0
;
unsigned
int
outputlen
=
0
;
int
desc
=
0
,
alpha
=
0
;
int
limit_start
=
0
,
limit_count
=
-
1
,
start
,
end
;
int
j
,
dontsort
=
0
,
vectorlen
;
...
...
@@ -7280,7 +7280,7 @@ static void sortCommand(redisClient *c) {
/* Load the sorting vector with all the objects to sort */
switch
(
sortval
->
type
)
{
case
REDIS_LIST
:
vectorlen
=
l
istLength
((
list
*
)
sortval
->
ptr
);
break
;
case
REDIS_LIST
:
vectorlen
=
l
Length
(
sortval
);
break
;
case
REDIS_SET
:
vectorlen
=
dictSize
((
dict
*
)
sortval
->
ptr
);
break
;
case
REDIS_ZSET
:
vectorlen
=
dictSize
(((
zset
*
)
sortval
->
ptr
)
->
dict
);
break
;
default:
vectorlen
=
0
;
redisPanic
(
"Bad SORT type"
);
/* Avoid GCC warning */
...
...
@@ -7289,18 +7289,15 @@ static void sortCommand(redisClient *c) {
j
=
0
;
if
(
sortval
->
type
==
REDIS_LIST
)
{
list
*
list
=
sortval
->
ptr
;
listNode
*
ln
;
listIter
li
;
listRewind
(
list
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
robj
*
ele
=
ln
->
value
;
vector
[
j
].
obj
=
ele
;
lIterator
*
li
=
lInitIterator
(
sortval
,
0
,
REDIS_TAIL
);
lEntry
entry
;
while
(
lNext
(
li
,
&
entry
))
{
vector
[
j
].
obj
=
lGet
(
&
entry
);
vector
[
j
].
u
.
score
=
0
;
vector
[
j
].
u
.
cmpobj
=
NULL
;
j
++
;
}
lReleaseIterator
(
li
);
}
else
{
dict
*
set
;
dictIterator
*
di
;
...
...
@@ -7410,8 +7407,12 @@ static void sortCommand(redisClient *c) {
}
}
}
else
{
robj
*
listObject
=
createListObject
();
list
*
listPtr
=
(
list
*
)
listObject
->
ptr
;
robj
*
sobj
;
if
(
outputlen
>
server
.
list_max_ziplist_entries
)
{
sobj
=
createListObject
();
}
else
{
sobj
=
createZiplistObject
();
}
/* STORE option specified, set the sorting result as a List object */
for
(
j
=
start
;
j
<=
end
;
j
++
)
{
...
...
@@ -7419,31 +7420,30 @@ static void sortCommand(redisClient *c) {
listIter
li
;
if
(
!
getop
)
{
listAddNodeTail
(
listPtr
,
vector
[
j
].
obj
);
incrRefCount
(
vector
[
j
].
obj
);
}
listRewind
(
operations
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisSortOperation
*
sop
=
ln
->
value
;
robj
*
val
=
lookupKeyByPattern
(
c
->
db
,
sop
->
pattern
,
vector
[
j
].
obj
);
lPush
(
sobj
,
vector
[
j
].
obj
,
REDIS_TAIL
);
}
else
{
listRewind
(
operations
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
redisSortOperation
*
sop
=
ln
->
value
;
robj
*
val
=
lookupKeyByPattern
(
c
->
db
,
sop
->
pattern
,
vector
[
j
].
obj
);
if
(
sop
->
type
==
REDIS_SORT_GET
)
{
if
(
!
val
)
{
listAddNodeTail
(
listPtr
,
createStringObject
(
""
,
0
));
if
(
sop
->
type
==
REDIS_SORT_GET
)
{
if
(
!
val
)
val
=
createStringObject
(
""
,
0
);
/* lPush does an incrRefCount, so we should take care
* care of the incremented refcount caused by either
* lookupKeyByPattern or createStringObject("",0) */
lPush
(
sobj
,
val
,
REDIS_TAIL
);
decrRefCount
(
val
);
}
else
{
/* We should do a incrRefCount on val because it is
* added to the list, but also a decrRefCount because
* it is returned by lookupKeyByPattern. This results
* in doing nothing at all. */
listAddNodeTail
(
listPtr
,
val
);
/* always fails */
redisAssert
(
sop
->
type
==
REDIS_SORT_GET
);
}
}
else
{
redisAssert
(
sop
->
type
==
REDIS_SORT_GET
);
/* always fails */
}
}
}
if
(
dictReplace
(
c
->
db
->
dict
,
storekey
,
listObject
))
{
if
(
dictReplace
(
c
->
db
->
dict
,
storekey
,
sobj
))
{
incrRefCount
(
storekey
);
}
/* Note: we add 1 because the DB is dirty anyway since even if the
...
...
@@ -7454,6 +7454,9 @@ static void sortCommand(redisClient *c) {
}
/* Cleanup */
if
(
sortval
->
type
==
REDIS_LIST
)
for
(
j
=
0
;
j
<
vectorlen
;
j
++
)
decrRefCount
(
vector
[
j
].
obj
);
decrRefCount
(
sortval
);
listRelease
(
operations
);
for
(
j
=
0
;
j
<
vectorlen
;
j
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录