mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 16:40:50 +00:00
STRLEN command implemented
This commit is contained in:
parent
e0be2289e9
commit
80091bbaac
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user