mirror of
https://github.com/fluencelabs/redis
synced 2025-04-04 00:31:03 +00:00
Use helper function for string object length
This commit is contained in:
parent
1333f98dd2
commit
ad1b4f4f59
@ -215,21 +215,14 @@ void setrangeCommand(redisClient *c) {
|
|||||||
o = createObject(REDIS_STRING,sdsempty());
|
o = createObject(REDIS_STRING,sdsempty());
|
||||||
dbAdd(c->db,c->argv[1],o);
|
dbAdd(c->db,c->argv[1],o);
|
||||||
} else {
|
} else {
|
||||||
int olen;
|
size_t olen;
|
||||||
|
|
||||||
/* Key exists, check type */
|
/* Key exists, check type */
|
||||||
if (checkType(c,o,REDIS_STRING))
|
if (checkType(c,o,REDIS_STRING))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Find out existing value length */
|
|
||||||
if (o->encoding == REDIS_ENCODING_INT) {
|
|
||||||
char llbuf[32];
|
|
||||||
olen = ll2string(llbuf,sizeof(llbuf),(long)o->ptr);
|
|
||||||
} else {
|
|
||||||
olen = sdslen(o->ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return existing string length when setting nothing */
|
/* Return existing string length when setting nothing */
|
||||||
|
olen = stringObjectLen(o);
|
||||||
if (sdslen(value) == 0) {
|
if (sdslen(value) == 0) {
|
||||||
addReplyLongLong(c,olen);
|
addReplyLongLong(c,olen);
|
||||||
return;
|
return;
|
||||||
@ -433,18 +426,8 @@ void appendCommand(redisClient *c) {
|
|||||||
|
|
||||||
void strlenCommand(redisClient *c) {
|
void strlenCommand(redisClient *c) {
|
||||||
robj *o;
|
robj *o;
|
||||||
|
|
||||||
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||||
checkType(c,o,REDIS_STRING)) return;
|
checkType(c,o,REDIS_STRING)) return;
|
||||||
|
addReplyLongLong(c,stringObjectLen(o));
|
||||||
if (o->encoding == REDIS_ENCODING_RAW) {
|
|
||||||
addReplyLongLong(c,sdslen(o->ptr));
|
|
||||||
} else if (o->encoding == REDIS_ENCODING_INT) {
|
|
||||||
char llbuf[32];
|
|
||||||
int len = ll2string(llbuf,sizeof(llbuf),(long)o->ptr);
|
|
||||||
addReplyLongLong(c,len);
|
|
||||||
} else {
|
|
||||||
redisPanic("Unknown string encoding");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user