In Redis, BigKeys consume excessive memory resources, which affects the performance and availability of Redis.
Generally speaking, the following conditions may cause a key to be considered a BigKey:
Note: These thresholds are not rigid rules and should be judged based on your actual situation to determine whether a key qualifies as a BigKey.
Use the following command to sample and check the keys in Redis, identifying those that occupy a large amount of memory, along with their types and sizes.
For more detailed methods of detecting BigKeys, refer to .
BigKey Type | Repair Methods |
---|---|
String | Consider splitting the BigKey into multiple smaller strings for storage. Use the GETRANGE and SETRANGE commands to read and modify parts of the string, thereby breaking a large string into several smaller strings. |
Hash | Split the BigKey into several smaller hashes. First, break the key set of the large hash into parts, then split the field sets of each key's corresponding hash, and finally break each field's corresponding value into parts. This way, a large hash can be divided into several smaller hashes. |
List | Consider splitting the BigKey into several smaller lists for storage. Use the LRANGE and RPUSH commands to read and modify parts of the list, thereby segmenting a large list into several smaller lists. |
Set | Consider splitting the BigKey into several smaller sets for storage. Use the SMEMBERS and SADD commands to read and modify elements in the set, thereby dividing a large set into several smaller sets. |
Sorted Set | Split the BigKey into several smaller sorted sets. First, partition the key set of the large sorted set, then split the elements of each key's corresponding sorted set. Use the ZRANGE and ZADD commands to read and modify the elements in the sorted set, thus dividing a large sorted set into several smaller sorted sets. |