Redis BigKey

Introduction to BigKey

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:

  • For string type keys, if the allocated memory exceeds 5 MB.
  • For list type keys, if the number of elements exceeds 20,000, or the allocated memory exceeds 1 MB.
  • For set type keys, if the number of elements exceeds 5,000, or the allocated memory exceeds 1 MB.
  • For sorted set type keys, if the number of elements exceeds 10,000, or the allocated memory exceeds 1 MB.
  • For hash type keys, if the number of fields exceeds 1,000, or the allocated memory exceeds 1 MB.

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.

How to identify BigKeys in a Redis instance?

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.

redis-cli --bigkeys

For more detailed methods of detecting BigKeys, refer to .

How to fix BigKeys in a Redis instance?

BigKey TypeRepair Methods
StringConsider 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.
HashSplit 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.
ListConsider 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.
SetConsider 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 SetSplit 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.