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
ad1b4f4f
Commit
ad1b4f4f
authored
Dec 15, 2010
by
Pieter Noordhuis
Browse files
Use helper function for string object length
parent
1333f98d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
ad1b4f4f
...
...
@@ -215,21 +215,14 @@ void setrangeCommand(redisClient *c) {
o
=
createObject
(
REDIS_STRING
,
sdsempty
());
dbAdd
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
else
{
in
t
olen
;
size_
t
olen
;
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
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 */
olen
=
stringObjectLen
(
o
);
if
(
sdslen
(
value
)
==
0
)
{
addReplyLongLong
(
c
,
olen
);
return
;
...
...
@@ -433,18 +426,8 @@ void appendCommand(redisClient *c) {
void
strlenCommand
(
redisClient
*
c
)
{
robj
*
o
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
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"
);
}
addReplyLongLong
(
c
,
stringObjectLen
(
o
));
}
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