

Ask HN: What internal data structures does redis use to make it so fast? - nojvek

I&#x27;m wondering how reddit stores its datastructures in memory to make it so fast.If I were to extend redis to store proper tables and json in binary format, how would I do that.<p>Also as a learning exercise how do I make a pure disk based redis. e.g the way sqlite is to sql
======
striking
Read the code yourself here:
[https://github.com/antirez/redis/blob/unstable/src/dict.c](https://github.com/antirez/redis/blob/unstable/src/dict.c)
(It's a classic hashmap.)

JSON in binary format? You mean BSON? Just use MongoDB at that point, or
PostgreSQL with JSON support. Redis has tables to an extent, you don't need
any more than that.

Also, running on disk versus in memory is very different. Writing in SQLite is
done to a Write-Ahead Log and then committed into the file slowly. Reads are
done by building a schema to a set of pointer additions and finding objects in
b-trees by scanning both the in-memory cache as well as objects on the hard
drive. Totally, totally different. Just use the Redis Serialization feature
instead. Or, better yet, use MongoDB/PostgreSQL/SQLite as intended.

Aside: the whole point of the Structured Query Language is to take away the
lowest level, most basic work from the programmer. That way, he or she can
write the logic without worrying about how the logic is performed. Why redo
all of that work? SQL exists for a reason: so you don't reinvent the wheel.

