Skip to content

number limit difference between redis and javascript #339

@alyc

Description

@alyc

Hi,

In redis as per doc http://redis.io/commands/incr
the limit is 64 bit signed integer, max is 2^63 = 9 223 372 036 854 775 807

But for javascript, the max is 2^53 = 9 007 199 254 740 992
http://blog.vjeux.com/2010/javascript/javascript-max_int-number-limits.html

You can see the problem here when I increment the value beyond 2^53, it will not hit error, but it will loose precision.

If I call hincrby by 1 several time, I get the following strange result.
9007199254740991
9007199254740992
9007199254740992 <--- the last digit suppose to be 3
9007199254740994

I was wondering is there a way to overcome this javascript limit? Could node_redis return string instead of number to retain the precision if the number return goes beyond the limit? Since the are other tools we can use like bignum to do the operation that we need.

Kind Regards
Andy

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions