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
a400a9b2
Commit
a400a9b2
authored
Feb 16, 2012
by
antirez
Browse files
Now HINCRBY can detect overflows too. Fix for issue #330.
parent
6e09ad1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_hash.c
View file @
a400a9b2
...
@@ -320,7 +320,7 @@ void hmsetCommand(redisClient *c) {
...
@@ -320,7 +320,7 @@ void hmsetCommand(redisClient *c) {
}
}
void
hincrbyCommand
(
redisClient
*
c
)
{
void
hincrbyCommand
(
redisClient
*
c
)
{
long
long
value
,
incr
;
long
long
value
,
incr
,
oldvalue
;
robj
*
o
,
*
current
,
*
new
;
robj
*
o
,
*
current
,
*
new
;
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
incr
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
incr
,
NULL
)
!=
REDIS_OK
)
return
;
...
@@ -336,7 +336,12 @@ void hincrbyCommand(redisClient *c) {
...
@@ -336,7 +336,12 @@ void hincrbyCommand(redisClient *c) {
value
=
0
;
value
=
0
;
}
}
oldvalue
=
value
;
value
+=
incr
;
value
+=
incr
;
if
((
incr
<
0
&&
value
>
oldvalue
)
||
(
incr
>
0
&&
value
<
oldvalue
))
{
addReplyError
(
c
,
"increment or decrement would overflow"
);
return
;
}
new
=
createStringObjectFromLongLong
(
value
);
new
=
createStringObjectFromLongLong
(
value
);
hashTypeTryObjectEncoding
(
o
,
&
c
->
argv
[
2
],
NULL
);
hashTypeTryObjectEncoding
(
o
,
&
c
->
argv
[
2
],
NULL
);
hashTypeSet
(
o
,
c
->
argv
[
2
],
new
);
hashTypeSet
(
o
,
c
->
argv
[
2
],
new
);
...
...
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