URL seems broken now but article is here:<p><a href="http://web.archive.org/web/20180303001631/http://www.heychinaski.com/blog/2013/10/14/a-look-at-the-redis-source-code/" rel="nofollow">http://web.archive.org/web/20180303001631/http://www.heychin...</a>
Redis is my favorite example of a very clean and beautiful example of C code, just the right amount of comments, good variable names. It is great work. You can tell Salvatore cares and has passion for what he does just by looking at his work.<p><a href="https://github.com/antirez/redis/tree/unstable/src" rel="nofollow">https://github.com/antirez/redis/tree/unstable/src</a>
I'm certainly novice in C, but as I was reading, I wondered about this<p><pre><code> {"get",getCommand,2,"r",0,NULL,1,1,1,0,0},
"The fourth field, set to "r", is specifying that the
command is read only and doesn’t modify any keys’ value
or state. There are a whole bunch of one letter flags
that you can specify in this string that are explained
in detail in the nearby block comment. The field
following this string should always be set to zero, and
will be computed later. It’s simply a bitmask
representation of the information implied by the string."
</code></pre>
Why would you opt for this, when you could specify some constants and bitwise or them together? Isn't that a more common thing to do, than to calculate a bitwise flags at run time?<p><pre><code> COMMAND_READONLY | COMMAND_RANDOM | COMMAND_NOSIDEEFFECTS
</code></pre>
ect ect ect.<p>I'm sure there's a good reason, but this style seems strange to me.<p>Maybe redis makes use of the string later? but I can't help but feel it should build the string based on the flags, rather than build the flags based on the string.
Fun. This isn't really specific to Redis, but is a good introduction to the sort of thing that C programmers often get up to. You'll see this sort of function table in all sorts of C programs. Take a look at GNU stuff like make and you'll see the same format.<p>Congratulations on the exploring.
I find it fascinating to compare H2 and Derby source code. First was written by single man, has more features, is more compact and faster. Second was 'designed by committee' and evolved over long period of time.<p>I would also post link to my project, which is sort of 'Redis in Java', but it would be probably spam.
Nice post. I've been working quite a lot with the internals of Redis in the past few months. Adding custom commands along with the usual skimming through the builtins. Perhaps I should give people some insight by creating a few blog post as well. It's a really nice piece of software and written in clean, high quality, C. Not sure about the tests in Tcl though :).