Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when Int64 maxvalue is exceded with Redis INCR

Tags:

redis

Simple enough, I am using Redis INCR to ensure atomic increments of a counter, the counter has an indeterminate start value less than Int64.MaxValue.

Does Redis reset the value when it reaches Int64.MaxValue or throw an error?

I read the documentation but it does not say what happens, and I really do want to maintain the atomic nature at rollover

like image 910
Old fart Avatar asked Apr 26 '16 09:04

Old fart


1 Answers

It will throw an error. I did a small experiment for your use case

127.0.0.1:6379> set value 9223372036854775807 (2 power 63 -1)
OK
127.0.0.1:6379> incr value
(error) ERR increment or decrement would overflow
127.0.0.1:6379> 

Redis can hold upto 2 power 63. and throws error if it exceeds that limit. It might be either "out of range" error or "overflow" error

Upon error you can catch that exception and reset the value in your application logic.

like image 125
Karthikeyan Gopall Avatar answered Oct 05 '22 06:10

Karthikeyan Gopall