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
redis> SETBIT mykey3 7 0
(integer) 0
redis> SETBIT mykey3 7 1
(integer) 0
redis> GET mykey3
redis> SET mykey4 5
redis> SETBIT mykey4 7 0
(integer) 1
redis> GET mykey4

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?


If you look at bitops.c you'll see that indeed bit commands only work with string key type.


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.

Need Your Help

How to implement FOSUserBundle register form in other pages

php forms symfony2 fosuserbundle

So, I'm using the FOSUserBundle and I want to implement the register form in a pop-up module that will appear when the user clicks on a button so that he can register.

Clearing session cookies in the browser

php session session-cookies

I require some confirmation about sessions and session cookie logic.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.