提交 80091bba 编写于 作者: A antirez

STRLEN command implemented

上级 e0be2289
......@@ -74,6 +74,7 @@ struct redisCommand readonlyCommandTable[] = {
{"setex",setexCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,NULL,0,0,0},
{"append",appendCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,NULL,1,1,1},
{"substr",substrCommand,4,REDIS_CMD_INLINE,NULL,1,1,1},
{"strlen",strlenCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
{"del",delCommand,-2,REDIS_CMD_INLINE,NULL,0,0,0},
{"exists",existsCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
{"incr",incrCommand,2,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM,NULL,1,1,1},
......
......@@ -859,6 +859,7 @@ void blpopCommand(redisClient *c);
void brpopCommand(redisClient *c);
void appendCommand(redisClient *c);
void substrCommand(redisClient *c);
void strlenCommand(redisClient *c);
void zrankCommand(redisClient *c);
void zrevrankCommand(redisClient *c);
void hsetCommand(redisClient *c);
......
......@@ -252,4 +252,13 @@ void substrCommand(redisClient *c) {
decrRefCount(o);
}
void strlenCommand(redisClient *c) {
robj *o;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
checkType(c,o,REDIS_STRING)) return;
o = getDecodedObject(o);
addReplyLongLong(c,sdslen(o->ptr));
decrRefCount(o);
}
......@@ -368,4 +368,18 @@ start_server {tags {"basic"}} {
r expire z 10000
list [r msetnx x A y B z C] [r mget x y z]
} {0 {1 {} {}}}
test {STRLEN against non existing key} {
r strlen notakey
} {0}
test {STRLEN against integer} {
r set myinteger -555
r strlen myinteger
} {4}
test {STRLEN against plain string} {
r set mystring "foozzz0123456789 baz"
r strlen mystring
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册