hincrby with decimals

74 views
Skip to first unread message

Benjamin Polidore

unread,
Jul 8, 2011, 3:49:21 AM7/8/11
to redi...@googlegroups.com
I'm using the 2.2.111-scripting tag, and I can't do HINCRBY with a decimal.  For example:

redis 127.0.0.1:6379> hget account:h50 usd
"100"
redis 127.0.0.1:6379> HINCRBY account:h50 usd 22.01
(error) ERR value is not an integer or out of range

I'm pretty sure i used to be able to do this with the main branch.  Why not allow incrementing by a decimal?

Josiah Carlson

unread,
Jul 8, 2011, 7:09:12 AM7/8/11
to redi...@googlegroups.com

This hasn't been possible since at most 1.3.10 (I tried it then, found
it didn't work, and used zsets instead).

Regards,
- Josiah

Pieter Noordhuis

unread,
Jul 8, 2011, 8:39:26 AM7/8/11
to redi...@googlegroups.com
The INCR family uses 64-bit integers range. If you know what the
precision is you need up front, you can choose to store a multiple so
you don't need to work with floats. In the case of USD, you would be
storing cents instead.

Cheers,
Pieter

> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
>
>

Benjamin Polidore

unread,
Jul 8, 2011, 11:21:17 AM7/8/11
to redi...@googlegroups.com
Ok that makes sense. I can do that no problem. I guess my unit test
was flawed when I was using the main branch.
Reply all
Reply to author
Forward
0 new messages