High performance is the most prominent feature of Redis. Robust Redis performance is crucial to ensure the service availability. A reduced Redis performance can be caused by multiple reasons. The hotkey issue is one of the most common reasons. The discovery of hotkeys is the first step to improve Redis performance. This topic describes how to use the new features of Redis 4.0 to discover the hotkeys.

Note ApsaraDB for Redis now supports querying hotspot keys by using audit logs. This can help you query hotspot keys in the Redis service in an easy and accurate way. For more information, see Query the history of hot keys.

Background information

Redis 4.0 added two data eviction strategies: allkey-lfu and volatile-lfu. You can also run the OBJECT command to obtain the access frequency of a specific key, as shown in the following figure.

The native Redis client also added the --hotkeys option to help you discover hotkeys in your business.

Note This topic describes how to discover hotkeys to optimize the performance of Redis. This topic is suitable for users who are familiar with the basic features of ApsaraDB for Redis and are seeking advanced skills. If you are not familiar with Redis, we recommend that you read Product Overview and Quick Start.

Prerequisites

  • You have activated an Elastic Compute Service (ECS) instance that can connect to an ApsaraDB for Redis instance.
  • You have installed a Redis server whose version is later than 4.0 on the ECS instance.
    Note You can use redis-cli after Redis is installed on the ECS instance.
  • The maxmemory-policy parameter of the ApsaraDB for Redis instance is set to volatile-lfu or allkeys-lfu.
    Note For more information about how to modify the parameters, see Parameter overview and configuration guide.

Procedure

  1. You can use the following command to query the hotkeys when the ApsaraDB for Redis instance have running workloads.
    redis-cli -h r-***************.redis.rds.aliyuncs.com -a <password> --hotkeys
    Note This topic uses redis-benchmark to simulate a scenario that features a high volume of writes.
    Table 1. Option descriptions
    Option Description
    -h Specifies the endpoint of an ApsaraDB for Redis instance.
    -a Specifies the password of an ApsaraDB for Redis instance.
    --hotkeys Used to query hotkeys.

Results

The following example shows the result of running this command.

The summary part in the result displays the hotkeys.