redis 127.0.0.1:6379> set a 0 OK redis 127.0.0.1:6379> decrby a -9223372036854775807 (integer) 9223372036854775807 redis 127.0.0.1:6379> set a 0 OK redis 127.0.0.1:6379> decrby a -9223372036854775808 (integer) -9223372036854775808
The last decrby command should return out range error.
Comment From: anydot
Not and issue, minimal value for 64bit signed int really is "-9223372036854775808".
Comment From: jokea
That's true. But "0 - (-9223372036854775808)" should be 9223372036854775808, which can't be represented as a signed 64bit value and should report out-of-range error.
Comment From: rootslab
https://github.com/antirez/redis/blob/unstable/src/t_string.c#L249
@jokea a little mod could solve it ( incrDecrCommand function )
if ((incr < 0 && oldvalue <= 0 && incr < (LLONG_MIN-oldvalue+1)) ||
(incr > 0 && oldvalue >= 0 && incr > (LLONG_MAX-oldvalue))) {
...
redis> set a 0
OK
redis> decrby a -9223372036854775808
(error) ERR increment or decrement would overflow
redis> get a
"0"
Comment From: jokea
Thanks @rootslab.
Fixing it is simple, I want to make sure this is a bug and gets fixed in all redis versions.
Comment From: rootslab
Hi @jokea, since it's a minor bug/fix, I think it is useful to at least indicate the point in the code where it happens, or to send a simple pull request ;)