Search code examples
performanceredis

Performance Issues of Redis's HMGET Command


When I use the Redis HMGET command to retrieve data in a production environment, if the number of keys included in the command exceeds 10,000, and there is a high volume of requests, the CPU usage of Redis spikes dramatically.

I would like to know the specific reasons behind this phenomenon, because retrieving data from a hash table should be an O(1) time expense.


Solution

  • if the number of keys included in the command exceeds 10,000

    If I understand correctly, you mean the number of fields of a Redis HASH.

    retrieving data from a hash table should be O(1)

    Yes, the time complexity of getting a single field from hash table is O(1). However, you are retrieving 10,000 fields, and the time complexity should be 10,000 times larger than O(1).

    HMGET is a slow command, when the fields you need to retrieve a big number of fields. It blocks Redis, and you should use it with care on production env.