I. Overview
-The Redis source code version is 3.0.0.
- Redis hash command please poke.
- the OBJECT the ENCODING Key to view the underlying data type implementations.
Two: summary
-When using Hash
- controlling the size of the data, so as not to exceed not write hash-max-ziplist-value byte configuration.
- controlling the number of hash, try not to write not exceed hash-max-ziplist-entries number of configurations.
-Otherwise, it will cause changes in the underlying data structure and lead to increased memory consumption. At the same time , too much data and too many data will reduce hash performance .
Two: the underlying implementation of hash objects
- Encoding
-There are three encoding methods for string objects: ziplist (compression list) / hashtable (underlying dictionary implementation)
-Selection of encoding method
-When the elements of the hash object are less than 64 bytes (hash-max-ziplist-value) / the number of elements is less than 512 (hash-max-ziplist-entries), use ziplist
-Use hashtable if the conditions are not met.
- ziplist encoding
-Developed to save memory , a sequential data structure consisting of a series of specially coded consecutive memory blocks .
-Save process
-Every time a new hash node is added, the hash key / hash value will be pushed to the end of the compressed list. (Class queue)
-Icon
-
-hashtable encoding
-Hastable uses a dictionary as the underlying implementation, and each key value in the hash is saved with a dictionary key value.
-Icon
-
Four: code conversion
- When ziplist greater than 64/512 will be greater than the length encoding conversion ziplist -> hashtable.
Five: the realization of string commands
-