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
b215a496
Commit
b215a496
authored
Dec 10, 2010
by
antirez
Browse files
faster INCR doing far less allocation in common cases
parent
dd48de74
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
b215a496
...
...
@@ -144,8 +144,23 @@ void incrDecrCommand(redisClient *c, long long incr) {
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
if
(
o
!=
NULL
&&
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
/* Fast path if the object is integer encoded and is not shared. */
if
(
o
&&
o
->
refcount
==
1
&&
o
->
encoding
==
REDIS_ENCODING_INT
)
{
long
long
newval
=
((
long
)
o
->
ptr
)
+
incr
;
if
(
newval
>=
LONG_MIN
&&
newval
<=
LONG_MAX
)
{
o
->
ptr
=
(
void
*
)
(
long
)
newval
;
touchWatchedKey
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
addReplyLongLong
(
c
,
newval
);
return
;
}
/* ... else take the usual safe path */
}
/* Otherwise we create a new object and replace the old one. */
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
value
+=
incr
;
o
=
createStringObjectFromLongLong
(
value
);
dbReplace
(
c
->
db
,
c
->
argv
[
1
],
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