NOTE

3.5 Redis bigkey

What a Redis big key is, its risks, how to find and delete it, and the basic mitigation of splitting it into smaller keys.

Redis / CacheCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What Is a Big Key?

  • This is about the value:
    • string type: generally considered big when it exceeds 10 KB;
    • other types: too many elements.

2. Risks of a Big Key

  • Timeout and blocking: operating on a big key is time-consuming.
  • Uneven memory allocation: for example, under Redis Cluster mode.
  • Is the bottleneck for reading/writing a big key CPU or bandwidth? Below xx bandwidth, bandwidth becomes full first; above xx, CPU becomes full first.

3. How to Find a Big Key

  • scan + debug object: on a replica node, use scan for incremental scanning, then use debug object to calculate whether each key’s serializedlength attribute is too large.
  • redis-cli provides --bigkeys, for example: redis-cli -h <hostip> -a <password> --bigkeys.

4. How to Delete a Big Key

  • string: use del.
  • others: hscan + hdel + del.

5. How to Solve a Big Key

5.1. Split It into Smaller Keys

6. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub