Open GoogleCodeExporter opened 8 years ago
incr and incrby only work on 64 bit signed integers not floats, see
http://redis.io/commands/incrby and http://redis.io/commands/incr
Original comment by rowan%wo...@gtempaccount.com
on 15 Mar 2011 at 12:27
is there any function available for increment by float just like increment by
integer value?
Original comment by vai.gol...@gmail.com
on 15 Mar 2011 at 12:29
No, if you need an atomic float increment you're best off using something like
WATCH key
$var = GET key
MULTI
SET key $var+0.3
EXEC
Original comment by rowan%wo...@gtempaccount.com
on 15 Mar 2011 at 12:33
Another approach would be to use a multiplying factor to convert floats to
ints, as big as the needed precision you want. I use 10000.
Original comment by dvir...@gmail.com
on 15 Mar 2011 at 12:37
Th problem is using step by step Get and Set is, By the time script set the
value It might have been changed from what is fetched in get. Specially in
multi process environment we might end up setting wrong or old value.
A new IncrFloat would be best or getset accept mathematical operator like
getset +0.3
Original comment by vai.gol...@gmail.com
on 15 Mar 2011 at 12:38
Yeah Dvirsky, We are using a similar approach of x1000. but having some
incrbyfloat would be best if possible.
Original comment by vai.gol...@gmail.com
on 15 Mar 2011 at 12:40
Thats why you use WATCH
Here is some pseudo code
$success = null
while($success == null)
{
WATCH key
$var = GET key
MULTI
SET key $var+0.3
$success = EXEC
}
It will keep getting/setting until it sets successfully, the WATCH statement
will cause the MULTI EXEC statement to return null if key is changed by another
process.
Original comment by rowan%wo...@gtempaccount.com
on 15 Mar 2011 at 12:49
Watch make sense.. Thanks Rowan!!!
Original comment by vai.gol...@gmail.com
on 15 Mar 2011 at 12:56
Just a random thought, but you may be able to treat the float value as a 64bit
int in your redisclient (i.e. by coercing the 64bit int into a 64bit float) and
then work out the incremental difference on the redisclient then send that
value to Redis with INCRBY?
Original comment by demis.be...@gmail.com
on 15 Mar 2011 at 12:57
I agree that this feature request would be handy, and would round out the incr*
operators nicely. Especially useful for keeping tracks of stats and money.
Original comment by findch...@gmail.com
on 13 Sep 2011 at 7:04
Hello, this feature is accepted. We'll have INCRBYFLOAT for 2.6.
Maybe we'll back port the feature into 2.4 at some point, I'm not sure.
Thanks for the input!
Salvatore
Original comment by anti...@gmail.com
on 15 Sep 2011 at 3:06
Original issue reported on code.google.com by
vai.gol...@gmail.com
on 15 Mar 2011 at 10:58