hash is a string type field and value mapping table. Both add and remove operations have O(1) (average) complexity. The hash type is particularly suitable for storing objects. When the number of fields is within the limit and the length of the value is less than the specified number of bytes, the hash type at this time is stored using zipmap, so it will save memory. You can modify the configuration items in the configuration file to control the number of fields and the number of bytes of the value.
hash-max-zipmap-entries 512 #The maximum number of configuration fields is 512
hash-max-zipmap-value 64 #The maximum configuration value is 64 bytes.
The above two conditions must be met, then the key will be compressed. Otherwise, the hash type key is stored according to the normal hash structure.
[Note] These two configurations do not limit the maximum number of fields that the hash structure can store and the maximum number of bytes of value. They mean that the number of fields does not exceed the configured number, and each When the length of the value corresponding to field is less than the specified number of bytes, note that when both conditions are met, the key is stored using zipmap, which is compressed data to save space. When the number of fields exceeds, or the length of a value is greater than the specified length, the entire key will be stored in memory using a normal hash structure.
Redis hash is a mapping table of string type fields and values. Hash is particularly suitable for storing objects.
Each hash in Redis can store 232 - 1 key-value pairs (more than 4 billion).
Example
127.0.0.1:6379> HMSET Rediskey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000 OK 127.0.0.1:6379> HGETALL Rediskey 1) "name" 2) "redis tutorial" 3) "description" 4) "redis basic commands for caching" 5) "likes" 6) "20" 7) "visitors" 8) "23000"
The above is the detailed content of How many fields can be stored in a hash in redis?. For more information, please follow other related articles on the PHP Chinese website!