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
3d6eade7
Commit
3d6eade7
authored
Mar 08, 2011
by
Pieter Noordhuis
Browse files
Don't encode element argument when dealing with ziplist
parent
6b017e61
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
3d6eade7
...
@@ -560,11 +560,16 @@ int zzlInsert(robj *zobj, robj *ele, double score) {
...
@@ -560,11 +560,16 @@ int zzlInsert(robj *zobj, robj *ele, double score) {
*----------------------------------------------------------------------------*/
*----------------------------------------------------------------------------*/
/* This generic command implements both ZADD and ZINCRBY. */
/* This generic command implements both ZADD and ZINCRBY. */
void
zaddGenericCommand
(
redisClient
*
c
,
robj
*
key
,
robj
*
ele
,
double
score
,
int
incr
)
{
void zaddGenericCommand(redisClient *c, int incr) {
static char *nanerr = "resulting score is not a number (NaN)";
static char *nanerr = "resulting score is not a number (NaN)";
robj *key = c->argv[1];
robj *ele;
robj *zobj;
robj *zobj;
robj *curobj;
robj *curobj;
double
curscore
=
0
.
0
;
double score, curscore = 0.0;
if (getDoubleFromObjectOrReply(c,c->argv[2],&score,NULL) != REDIS_OK)
return;
zobj = lookupKeyWrite(c->db,key);
zobj = lookupKeyWrite(c->db,key);
if (zobj == NULL) {
if (zobj == NULL) {
...
@@ -580,6 +585,8 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
...
@@ -580,6 +585,8 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *eptr;
unsigned char *eptr;
/* Prefer non-encoded element when dealing with ziplists. */
ele = c->argv[3];
if ((eptr = zzlFind(zobj,ele,&curscore)) != NULL) {
if ((eptr = zzlFind(zobj,ele,&curscore)) != NULL) {
if (incr) {
if (incr) {
score += curscore;
score += curscore;
...
@@ -620,6 +627,7 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
...
@@ -620,6 +627,7 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
zskiplistNode *znode;
zskiplistNode *znode;
dictEntry *de;
dictEntry *de;
ele = c->argv[3] = tryObjectEncoding(c->argv[3]);
de = dictFind(zs->dict,ele);
de = dictFind(zs->dict,ele);
if (de != NULL) {
if (de != NULL) {
curobj = dictGetEntryKey(de);
curobj = dictGetEntryKey(de);
...
@@ -672,17 +680,11 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
...
@@ -672,17 +680,11 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
}
}
void zaddCommand(redisClient *c) {
void zaddCommand(redisClient *c) {
double
scoreval
;
zaddGenericCommand(c,0);
if
(
getDoubleFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
scoreval
,
NULL
)
!=
REDIS_OK
)
return
;
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
zaddGenericCommand
(
c
,
c
->
argv
[
1
],
c
->
argv
[
3
],
scoreval
,
0
);
}
}
void zincrbyCommand(redisClient *c) {
void zincrbyCommand(redisClient *c) {
double
scoreval
;
zaddGenericCommand(c,1);
if
(
getDoubleFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
scoreval
,
NULL
)
!=
REDIS_OK
)
return
;
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
zaddGenericCommand
(
c
,
c
->
argv
[
1
],
c
->
argv
[
3
],
scoreval
,
1
);
}
}
void zremCommand(redisClient *c) {
void zremCommand(redisClient *c) {
...
...
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