The underlying storage of Redis
Redis stores all of the keys in a large dictionary. If you’ve learned Python, you’ll probably know that the dictionary is a different data structure from the Python dictionary.
As shown in the figure:
We can see that the structure is array + linked list, we know that the Java HashMap each expansion is greater than the LoadFactor threshold, we need to reallocate a 2 times array, we need to rehash all elements into a new array, the size of the array is 2N, Double the size of the space and it becomes 2n plus 1
What is an incremental hash?
We know that Java HashMap is to rehash all the elements at once and then add them to the new array. When the HashMap has many elements, there will be a phenomenon of thread stall
Incremental Hash it will also create a new array when expanding, but it will keep both the old and the new array, and then gradually migrate the elements mounted in the old array to the new array during scheduled tasks and Hash instructions. In Redis, there will be two underlying arrays when expanding. So when you’re accessing both the new array and the old array, if you can’t find an element in the old array you’re going to look for an element in the new array, so what happens when you find an element in the old array? Redis will add the elements of the old array to that location by performing a hash operation on the new array, and then slowly add the elements of the old array to the new array. This is a progressive hash. The underlying implementation of MAP in GO is also a progressive hash. So Reids is twice as big as HashMap