Reading Redis #1
The author of 8cc had wrote his experience of reading Gauche from the top to the bottom. I haven’t have such a codebase, and I’d like to have.
From today, I’d like to start reading Redis. Why Redis?
- I haven’t use Redis much, but I like the author and his writings. I love the Redis manifestro.
 - I’d like to learn how to write a good server.
 - Contains many algorithms and data structures from lists to HyperLogLogs (what is it? sounds too cool…)
 - It doesn’t have many dependencies.
 - It’s small and new.
 
Apparently there is a predecessor, who fixed the HelthCare.gov.
But I don’t care. How many people read “The Catcher in the Rye” before me?
Files
% git log -1
commit 1fab07e078f35e175b8b09db3955dd654ced82c2
Author: antirez <antirez@gmail.com>
Date:   Wed Apr 1 07:01:44 2015
    Redis 3.0.0.
% ls
00-RELEASENOTES         Makefile                runtest-sentinel*
BUGS                    README                  sentinel.conf
CONTRIBUTING            deps/                   src/
COPYING                 redis.conf              tests/
INSTALL                 runtest*                utils/
MANIFESTO               runtest-cluster*
% 
src/ has Redis, deps/ has Redis’ dependeicies that are
- hiredis/ - Redis’ C client library
 - jemalloc/ - Jason Evans’ malloc which is used by FreeBSD’s libc and Firefox
 - linenoise/ - Redis’ readline replacement
 - lua/ - Lua programming language
 
I might skip jemalloc/ and lua/ since both are large, and they are pretty independent from Redis.
tests/ has Redis’ tests that are written in Tcl. utils/ contains random scripts that are written in sh, Tcl, or Ruby.
One of the interesting things here is, the lack of GNU autoconf. Redis’ Makefiles are nicely hand-written!
What’s next?
Let me read the main() function first.
% git grep 'main(' src/**/*.c
src/config.c:533:            /* argc == 1 is handled by main() as we need to enter the sentinel
src/crc64.c:186:int main(void) {
src/endianconv.c:107:int main(void) {
src/intset.c:351:int main(int argc, char **argv) {
src/redis-benchmark.c:633:int main(int argc, const char **argv) {
src/redis-check-aof.c:149:int main(int argc, char **argv) {
src/redis-check-dump.c:711:int main(int argc, char **argv) {
src/redis-cli.c:2171: * Program main()
src/redis-cli.c:2174:int main(int argc, char **argv) {
src/redis.c:3570:int main(int argc, char **argv) {
src/sds.c:970:int main(void) {
src/sha1.c:204:main(int argc, char **argv)
src/util.c:684:int main(int argc, char **argv) {
src/ziplist.c:1086:int main(int argc, char **argv) {
src/zipmap.c:407:int main(void) {
%
Apparently there are main() functions.