I am trying to store a number as a value in Redis key. For example, I want to store a value of 4. and I don't want it to be stored as "4". Why I need this? Because when I retrieve this value back, I will be doing some bitwise op on it. If it stores as "4" (instead of 4), the value actually stored in Redis seems to be 52 (that is... 00110100 instead of 00000100).
You might wonder, why I don't use Redis bitops. The reason is I have to store an array of many bits. I don't want to be doing redis bitops in a loop. I just want to locally create an equivalent array and upload it by calling set command.
In Javascript, I tried doing
redis.set(key, 4)
obviously it didn't work. Then I tried
redis.set(key, "\x04")
This works. But how do I store an array of bytes by converting to this format? What am I missing here?