I'm working with redis lua and need to perform bitwise logic operations on a field up to 53 bits(the default length of integer part of redis ordered set score)
But it seems I'm out of luck:
127.0.0.1:6379> eval 'return bit.lshift(1, 30) ' 0
(integer) 1073741824
127.0.0.1:6379> eval 'return bit.lshift(1, 31) ' 0
(integer) -2147483648
It seems bit.* can operate only on 30 bits and then overflows(32 bit signed integer)
I'm using Linux 64 bits and redis is compiled for 64 bits as well. It looks like a limitation of bit library:
http://bitop.luajit.org/api.html
Note that all bit operations return signed 32 bit numbers (rationale). And these print as signed decimal numbers by default.
On the other hand...
eval 'return math.pow(2, 53) ' 0
(integer) 9007199254740992
Any idea how better to overcome this problem?
P.S. someone would say move this logic to client - but I can't. The piece is pretty complicated and needs to work closely to data