Home  >  Article  >  Database  >  How many fields can be stored in a hash in redis?

How many fields can be stored in a hash in redis?

anonymity
anonymityOriginal
2019-06-05 10:36:0415362browse

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.

How many fields can be stored in a hash in redis?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn