Bottom: Dictionary

Bottom: Dictionary

Redis dictionary is the basis of the entire map, hash structure dependent on the dictionary, zset member to score the mapping is a dictionary. It is the underlying set of dictionaries, but the value is null.

A dictionary actually contains two internal hashtable, because expansion requires progressive volume reduction hash migration. hashtable by adding an array of linked lists components.

Progressive hash

When the rehash progressive, after the relocation operation in the program instructions trigger the dictionary, if not also the timing task.

When the expansion if redis are bgsave (background asynchronous data saved to disk), in order to minimize the separation pages, will try not to expansion, unless the hash table already crowded. Bgsave without scruples when volume reduction.

Traversal

When traversing the first traverse the old dictionary, then traverse the new. There are two traversal iterator: iterator security and insecurity iterators.

Security iterates over the course of the dictionary to find and can be modified and elements will not be repeated, when traversing security prevents dictionary rehash, the use of safety iterator while keys instruction execution, not allowing duplicate elements involved in persistence the operation will be safe to use iterators.

Unsafe iterators can only dictionary lookup element may be repeated, does not prevent rehash, such as scan command.

hash algorithm

redis hash algorithm uses a siphash algorithm, which is effective against the hash flooding attack, reduce bias hash function, even if the key is very little difference between these huge. (There is also a common hash algorithm is MD5)

Guess you like

Origin www.cnblogs.com/shizhuoping/p/11521175.html