Rate This Document
Findability
Accuracy
Completeness
Readability

Tuning the Redis Configuration

Adjust Redis parameters to improve the Redis performance.

The parameters of each Redis instance can be adjusted by modifying the file in the default configuration path /etc/redis.conf.

Choose appropriate synchronization policies based on Table 1 and your actual requirements.

Table 1 Redis instance parameters

Parameter

Default Value

Recommended Value

Description

appendfsync

everysec

everysec

Specifies the synchronization policy used when Redis writes data to drives. The options are as follows:

  • no: Redis does not perform drive synchronization but only writes data to the in-memory cache. The OS synchronizes data to drives only when necessary. This option is the fastest, but data will be lost when Redis restarts or breaks down.
  • always: Data is synchronized to the drives each time Redis performs a write operation, ensuring data persistence. This option is the most secure, but it deteriorates the Redis performance.
  • everysec: Redis synchronizes data to drives every second to ensure data persistence. This option is the default synchronization policy, which ensures data security and Redis performance to some extent.

appendonly

no

no

Indicates whether to enable the persistence function of Redis.

  • no: The persistence function of Redis is disabled.
  • yes: The persistence function of Redis is enabled. During Redis runtime, the append-only file is used to record all write operations.

save

save 900 1

save 300 10

save 60 10000

save ""

Saves data to drives.

  • By default, Redis automatically saves data based on the configured interval and number of modification times. For example, save 900 1 indicates that data is saved if it is modified at least once within 900 seconds.
  • It is recommended that this parameter be left empty (save ""). That is, do not use the automatic saving function of Redis but use other methods (such as manual saving or external backup tools) to back up data as required.

cluster-require-full-coverage

yes

yes

Indicates whether to allocate all slots in the cluster to nodes (that is, full coverage).

  • yes: All slots in the cluster must be allocated. Otherwise, the Redis cluster stops receiving query requests. In this case, if some instances in the cluster are faulty (for example, some slots are not covered), the entire cluster is unavailable. Once all slots are allocated, the cluster automatically becomes available.
  • no: Some slots are allowed to be unallocated, improving cluster availability.

maxmemory

1024

1024

Specifies the maximum memory size occupied by Redis, in MB.

maxmemory-policy

noeviction

noeviction

Specifies the policy for clearing data when the maximum memory limit is reached. The options are as follows:

  • volatile-lru: Use the LRU algorithm to select the key to be deleted from expired keys.
  • allkeys-lru: Use the LRU algorithm to select the key to be deleted from all keys.
  • volatile-random: Randomly select keys to be deleted from expired keys.
  • allkeys-random: Randomly select keys to be deleted from all keys.
  • volatile-ttl: Delete the key that expires the earliest.
  • allkeys-smart: Use the cooling algorithm to select one of all keys and delete it.
  • volatile-smart: Use the cooling algorithm to select one of the keys that have an expiration time and delete it.
  • noeviction: Do not delete any key and return an error when a write operation is performed.

rdbchecksum

yes

yes

Indicates whether to enable RDB checksum.

  • yes: This function is enabled.
  • no: This function is disabled.

rdbcompression

yes

yes

Indicates whether to compress data when Redis performs RDB persistence.

  • yes: This function is enabled.
  • no: This function is disabled.

stop-writes-on-bgsave-error

yes

yes

Specifies the action of handling an error that occurs when Redis performs a background persistence operation (bgsave).

  • yes: Redis stops accepting write operations when an error occurs in the persistence operation (bgsave) until the administrator manually rectifies the error.
  • no: Redis does not stop accepting write operations when an error occurs in the background persistence operation (bgsave). This means that even if bgsave fails, Redis continues to process write requests from the client instead of blocking or rejecting these requests.

activerehashing

no

no

Indicates whether to reset the hash table.

  • If this parameter is set to yes, Redis uses 1 ms CPU time to re-hash the Redis hash table every 100 ms, reducing the memory usage.
  • If the application scenario has strict time requirements, set this parameter to no. If the application scenario does not have strict time requirements, set this parameter to yes so that the memory can be released as quickly as possible.

activedefrag

no

no

Indicates whether to enable defragmentation.

  • yes: Redis automatically performs defragmentation when the memory usage exceeds the threshold to reduce memory fragments and improve memory utilization.
  • no: Automatic memory defragmentation is disabled for Redis.