In the first part I said that the hash table is a bit LIST, SET and SORTED SET. Judge for yourself - LIST is composed of ziplist / linkedlist, SET consists of dict / intset, and SORTED SET is ziplist / skiplist. We have already discussed Dictionary (dict), and in the second part of the article we consider the structure of ziplist - the second most common structure is applicable under the hood of Redis. Look at LIST - the second part of his “kitchen” is a simple implementation of a linked list. It is useful to us to carefully consider the often mentioned advice about the optimization of hash table by replacing them on the list. Calculate how much memory is required for overhead costs by using these structures, what price you pay for saving memory. To sum up when working with hash tables, using the ziplist encoding.
The last time we ended on that saved using ziplist 1,000,000* keys took 16 MB of RAM, while the dict the same data required 104 mb (ziplist 6 times smaller). Let’s understand what the price: