I am trying to store a negative value into a Redis bitset, but the operation fails with the following error:
bit offset is not an integer or out of range
Could some please explain why storing negative numbers in Redis bitsets isn’t supported?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because nobody refers to a position in a bitset using a negative number. A bitset in an array of bit, so its index is a positive integer.
If you have a negative number (for instance coming from a hashing function), then you need to convert it to an unsigned integer first. It is straightforward do to in most language.
In the specific case of Java, to cast a signed int to an unsigned value in the bottom 32 bits of a long, you need to AND with 0xffffffffL. See the following link:
Best way to convert a signed integer to an unsigned long?