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
752da584
Commit
752da584
authored
Dec 22, 2009
by
antirez
Browse files
ZRANGE, ZREVRANGE now support WITHSCORES options
parent
f6bea06f
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis-cli.c
View file @
752da584
...
@@ -96,9 +96,9 @@ static struct redisCommand cmdTable[] = {
...
@@ -96,9 +96,9 @@ static struct redisCommand cmdTable[] = {
{
"zincrby"
,
4
,
REDIS_CMD_BULK
},
{
"zincrby"
,
4
,
REDIS_CMD_BULK
},
{
"zrem"
,
3
,
REDIS_CMD_BULK
},
{
"zrem"
,
3
,
REDIS_CMD_BULK
},
{
"zremrangebyscore"
,
4
,
REDIS_CMD_INLINE
},
{
"zremrangebyscore"
,
4
,
REDIS_CMD_INLINE
},
{
"zrange"
,
4
,
REDIS_CMD_INLINE
},
{
"zrange"
,
-
4
,
REDIS_CMD_INLINE
},
{
"zrangebyscore"
,
-
4
,
REDIS_CMD_INLINE
},
{
"zrangebyscore"
,
-
4
,
REDIS_CMD_INLINE
},
{
"zrevrange"
,
4
,
REDIS_CMD_INLINE
},
{
"zrevrange"
,
-
4
,
REDIS_CMD_INLINE
},
{
"zcard"
,
2
,
REDIS_CMD_INLINE
},
{
"zcard"
,
2
,
REDIS_CMD_INLINE
},
{
"zscore"
,
3
,
REDIS_CMD_BULK
},
{
"zscore"
,
3
,
REDIS_CMD_BULK
},
{
"incrby"
,
3
,
REDIS_CMD_INLINE
},
{
"incrby"
,
3
,
REDIS_CMD_INLINE
},
...
...
redis.c
View file @
752da584
...
@@ -536,9 +536,9 @@ static struct redisCommand cmdTable[] = {
...
@@ -536,9 +536,9 @@ static struct redisCommand cmdTable[] = {
{"zincrby",zincrbyCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"zincrby",zincrbyCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"zrem",zremCommand,3,REDIS_CMD_BULK},
{"zrem",zremCommand,3,REDIS_CMD_BULK},
{"zremrangebyscore",zremrangebyscoreCommand,4,REDIS_CMD_INLINE},
{"zremrangebyscore",zremrangebyscoreCommand,4,REDIS_CMD_INLINE},
{"zrange",zrangeCommand,4,REDIS_CMD_INLINE},
{"zrange",zrangeCommand,
-
4,REDIS_CMD_INLINE},
{"zrangebyscore",zrangebyscoreCommand,-4,REDIS_CMD_INLINE},
{"zrangebyscore",zrangebyscoreCommand,-4,REDIS_CMD_INLINE},
{"zrevrange",zrevrangeCommand,4,REDIS_CMD_INLINE},
{"zrevrange",zrevrangeCommand,
-
4,REDIS_CMD_INLINE},
{"zcard",zcardCommand,2,REDIS_CMD_INLINE},
{"zcard",zcardCommand,2,REDIS_CMD_INLINE},
{"zscore",zscoreCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"zscore",zscoreCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
...
@@ -4531,6 +4531,14 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
...
@@ -4531,6 +4531,14 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
robj *o;
robj *o;
int start = atoi(c->argv[2]->ptr);
int start = atoi(c->argv[2]->ptr);
int end = atoi(c->argv[3]->ptr);
int end = atoi(c->argv[3]->ptr);
int withscores = 0;
if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) {
withscores = 1;
} else if (c->argc >= 5) {
addReply(c,shared.syntaxerr);
return;
}
o = lookupKeyRead(c->db,c->argv[1]);
o = lookupKeyRead(c->db,c->argv[1]);
if (o == NULL) {
if (o == NULL) {
...
@@ -4573,12 +4581,15 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
...
@@ -4573,12 +4581,15 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
ln = ln->forward[0];
ln = ln->forward[0];
}
}
addReplySds(c,sdscatprintf(sdsempty(),"*%d\r\n",rangelen));
addReplySds(c,sdscatprintf(sdsempty(),"*%d\r\n",
withscores ? (rangelen*2) : rangelen));
for (j = 0; j < rangelen; j++) {
for (j = 0; j < rangelen; j++) {
ele = ln->obj;
ele = ln->obj;
addReplyBulkLen(c,ele);
addReplyBulkLen(c,ele);
addReply(c,ele);
addReply(c,ele);
addReply(c,shared.crlf);
addReply(c,shared.crlf);
if (withscores)
addReplyDouble(c,ln->score);
ln = reverse ? ln->backward : ln->forward[0];
ln = reverse ? ln->backward : ln->forward[0];
}
}
}
}
...
...
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