Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
443c6409
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,发现更多精彩内容 >>
提交
443c6409
编写于
11月 01, 2009
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SORT STORE option
上级
d8f8b666
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
66 addition
and
40 deletion
+66
-40
TODO
TODO
+0
-1
redis-cli.c
redis-cli.c
+1
-0
redis.c
redis.c
+65
-39
未找到文件。
TODO
浏览文件 @
443c6409
...
...
@@ -21,7 +21,6 @@ LONG TERM TODO
* Add a command to inspect the currently selected DB index
* Consistent hashing implemented in all the client libraries having an user base
* SORT: Don't copy the list into a vector when BY argument is constant.
* SORT ... STORE keyname. Instead to return the SORTed data set it into key.
* Profiling and optimization in order to limit the CPU usage at minimum
* Write the hash table size of every db in the dump, so that Redis can resize the hash table just one time when loading a big DB.
* Elapsed time in logs for SAVE when saving is going to take more than 2 seconds
...
...
redis-cli.c
浏览文件 @
443c6409
...
...
@@ -239,6 +239,7 @@ static int cliReadReply(int fd) {
return
1
;
case
'+'
:
case
':'
:
printf
(
"(integer) "
);
return
cliReadSingleLineReply
(
fd
);
case
'$'
:
return
cliReadBulkReply
(
fd
);
...
...
redis.c
浏览文件 @
443c6409
...
...
@@ -172,11 +172,8 @@
/* Sort operations */
#define REDIS_SORT_GET 0
#define REDIS_SORT_DEL 1
#define REDIS_SORT_INCR 2
#define REDIS_SORT_DECR 3
#define REDIS_SORT_ASC 4
#define REDIS_SORT_DESC 5
#define REDIS_SORT_ASC 1
#define REDIS_SORT_DESC 2
#define REDIS_SORTKEY_MAX 1024
/* Log levels */
...
...
@@ -4447,7 +4444,7 @@ static void sortCommand(redisClient *c) {
int
limit_start
=
0
,
limit_count
=
-
1
,
start
,
end
;
int
j
,
dontsort
=
0
,
vectorlen
;
int
getop
=
0
;
/* GET operation counter */
robj
*
sortval
,
*
sortby
=
NULL
;
robj
*
sortval
,
*
sortby
=
NULL
,
*
storekey
=
NULL
;
redisSortObject
*
vector
;
/* Resulting vector to sort */
/* Lookup the key to sort. It must be of the right types */
...
...
@@ -4485,6 +4482,9 @@ static void sortCommand(redisClient *c) {
limit_start
=
atoi
(
c
->
argv
[
j
+
1
]
->
ptr
);
limit_count
=
atoi
(
c
->
argv
[
j
+
2
]
->
ptr
);
j
+=
2
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
j
]
->
ptr
,
"store"
)
&&
leftargs
>=
1
)
{
storekey
=
c
->
argv
[
j
+
1
];
j
++
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
j
]
->
ptr
,
"by"
)
&&
leftargs
>=
1
)
{
sortby
=
c
->
argv
[
j
+
1
];
/* If the BY pattern does not contain '*', i.e. it is constant,
...
...
@@ -4496,18 +4496,6 @@ static void sortCommand(redisClient *c) {
REDIS_SORT_GET
,
c
->
argv
[
j
+
1
]));
getop
++
;
j
++
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
j
]
->
ptr
,
"del"
)
&&
leftargs
>=
1
)
{
listAddNodeTail
(
operations
,
createSortOperation
(
REDIS_SORT_DEL
,
c
->
argv
[
j
+
1
]));
j
++
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
j
]
->
ptr
,
"incr"
)
&&
leftargs
>=
1
)
{
listAddNodeTail
(
operations
,
createSortOperation
(
REDIS_SORT_INCR
,
c
->
argv
[
j
+
1
]));
j
++
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
j
]
->
ptr
,
"get"
)
&&
leftargs
>=
1
)
{
listAddNodeTail
(
operations
,
createSortOperation
(
REDIS_SORT_DECR
,
c
->
argv
[
j
+
1
]));
j
++
;
}
else
{
decrRefCount
(
sortval
);
listRelease
(
operations
);
...
...
@@ -4614,6 +4602,8 @@ static void sortCommand(redisClient *c) {
/* Send command output to the output buffer, performing the specified
* GET/DEL/INCR/DECR operations if any. */
outputlen
=
getop
?
getop
*
(
end
-
start
+
1
)
:
end
-
start
+
1
;
if
(
storekey
==
NULL
)
{
/* STORE option not specified, sent the sorting result to client */
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"*%d
\r\n
"
,
outputlen
));
for
(
j
=
start
;
j
<=
end
;
j
++
)
{
listNode
*
ln
;
...
...
@@ -4636,10 +4626,46 @@ static void sortCommand(redisClient *c) {
addReply
(
c
,
val
);
addReply
(
c
,
shared
.
crlf
);
}
}
else
if
(
sop
->
type
==
REDIS_SORT_DEL
)
{
/* TODO */
}
else
{
assert
(
sop
->
type
==
REDIS_SORT_GET
);
/* always fails */
}
}
}
}
else
{
robj
*
listObject
=
createListObject
();
list
*
listPtr
=
(
list
*
)
listObject
->
ptr
;
/* STORE option specified, set the sorting result as a List object */
for
(
j
=
start
;
j
<=
end
;
j
++
)
{
listNode
*
ln
;
if
(
!
getop
)
{
listAddNodeTail
(
listPtr
,
vector
[
j
].
obj
);
incrRefCount
(
vector
[
j
].
obj
);
}
listRewind
(
operations
);
while
((
ln
=
listYield
(
operations
)))
{
redisSortOperation
*
sop
=
ln
->
value
;
robj
*
val
=
lookupKeyByPattern
(
c
->
db
,
sop
->
pattern
,
vector
[
j
].
obj
);
if
(
sop
->
type
==
REDIS_SORT_GET
)
{
if
(
!
val
||
val
->
type
!=
REDIS_STRING
)
{
listAddNodeTail
(
listPtr
,
createStringObject
(
""
,
0
));
}
else
{
listAddNodeTail
(
listPtr
,
val
);
incrRefCount
(
val
);
}
}
else
{
assert
(
sop
->
type
==
REDIS_SORT_GET
);
/* always fails */
}
}
}
dictReplace
(
c
->
db
->
dict
,
storekey
,
listObject
);
/* Note: we add 1 because the DB is dirty anyway since even if the
* SORT result is empty a new key is set and maybe the old content
* replaced. */
server
.
dirty
+=
1
+
outputlen
;
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%d
\r\n
"
,
outputlen
));
}
/* Cleanup */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录