How Redis represents String as bits internally?
I'm trying to understand the bit representation of a String (most specifically in Redis)
I tried this:
redis> SET mykey3 hello OK redis> SETBIT mykey3 7 0 (integer) 0 redis> SETBIT mykey3 7 1 (integer) 0 redis> GET mykey3 "iello" redis> SET mykey4 5 OK redis> SETBIT mykey4 7 0 (integer) 1 redis> GET mykey4 "4"
So what is the bit representation of "hello" and "5" in this case?
- Also how the other Redis types, List, Set, Sorted Set are represented as binary bit? Such that bit operations can work for it? Or this is not the case?
- From what is seems everything is stored as binary-safe String? If so, how does a List, Set, Sorted Set are represented as safe String?
All the following data types are supported as values:
- Binary-safe strings.
- Lists of binary-safe strings.
- Sets of binary-safe strings, that are collection of unique unsorted elements. You can think at this as a Ruby hash where all the keys are set to the 'true' value.
- Sorted sets, similar to Sets but where every element is associated to a floating number score. The elements are taken sorted by score. You can think of this as Ruby hashes where the key is the element and the value is the score, but where elements are always taken in order without requiring a sorting operation.
So only the lists and sets values are stored in binary-safe strings. This is also true for the keys and hash values as well as sorted set members.