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
80091bba
Commit
80091bba
authored
Jul 27, 2010
by
antirez
Browse files
STRLEN command implemented
parent
e0be2289
Changes
4
Show whitespace changes
Inline
Side-by-side
src/redis.c
View file @
80091bba
...
...
@@ -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
},
...
...
src/redis.h
View file @
80091bba
...
...
@@ -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
);
...
...
src/t_string.c
View file @
80091bba
...
...
@@ -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
);
}
tests/unit/basic.tcl
View file @
80091bba
...
...
@@ -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
}
}
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