TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A quick look at the Redis source code

149 pointsby HeyChinaskiover 11 years ago

11 comments

dangover 3 years ago
URL seems broken now but article is here:<p><a href="http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20180303001631&#x2F;http:&#x2F;&#x2F;www.heychinaski.com&#x2F;blog&#x2F;2013&#x2F;10&#x2F;14&#x2F;a-look-at-the-redis-source-code&#x2F;" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20180303001631&#x2F;http:&#x2F;&#x2F;www.heychin...</a>
rdtscover 11 years ago
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:&#x2F;&#x2F;github.com&#x2F;antirez&#x2F;redis&#x2F;tree&#x2F;unstable&#x2F;src</a>
评论 #6553590 未加载
评论 #6556312 未加载
jeremiepover 11 years ago
It&#x27;s actually a quick tutorial describing how to add a new command to Redis, not an actual analysis of the source code as I expected.
评论 #6553258 未加载
评论 #6553083 未加载
评论 #6553039 未加载
GhotiFishover 11 years ago
I&#x27;m certainly novice in C, but as I was reading, I wondered about this<p><pre><code> {&quot;get&quot;,getCommand,2,&quot;r&quot;,0,NULL,1,1,1,0,0}, &quot;The fourth field, set to &quot;r&quot;, 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.&quot; </code></pre> Why would you opt for this, when you could specify some constants and bitwise or them together? Isn&#x27;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&#x27;m sure there&#x27;s a good reason, but this style seems strange to me.<p>Maybe redis makes use of the string later? but I can&#x27;t help but feel it should build the string based on the flags, rather than build the flags based on the string.
评论 #6556659 未加载
jeanjqover 11 years ago
Fun. This isn&#x27;t really specific to Redis, but is a good introduction to the sort of thing that C programmers often get up to. You&#x27;ll see this sort of function table in all sorts of C programs. Take a look at GNU stuff like make and you&#x27;ll see the same format.<p>Congratulations on the exploring.
ethanazirover 11 years ago
I would buy a book written about Redis like this.
qwertaover 11 years ago
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 &#x27;designed by committee&#x27; and evolved over long period of time.<p>I would also post link to my project, which is sort of &#x27;Redis in Java&#x27;, but it would be probably spam.
malkiaover 11 years ago
Postgres source code has been pleasure to read, and the commit logs are outstanding.
elibenover 11 years ago
The Redis source code is very clean and readable. It&#x27;s a great example of how a non-trivial code base can be written in good C style.
pestrellaover 11 years ago
Excellent write up aimed at curious coders.
jahajaover 11 years ago
Nice post. I&#x27;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&#x27;s a really nice piece of software and written in clean, high quality, C. Not sure about the tests in Tcl though :).
评论 #6555393 未加载