Rate This Document
Findability
Accuracy
Completeness
Readability

Tuning the Redis Server

Purpose

You can adjust Redis parameters to improve the Redis performance.

Procedure

You can set the parameters of each Redis instance by editing the redis.conf file. Select the synchronization policy that is most suitable for your application scenario.

Parameter

Description

Default Value

Option

appendfsync

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.

everysec

  • no
  • always
  • everysec

appendonly

Indicates whether to enable the persistence function of Redis.

If this parameter is set to yes, Redis uses the append-only file to record all write operations when it is running.

no

  • yes
  • no

cluster-require-full-coverage

Indicates whether to allocate all slots in the cluster to nodes.

By default, if a slot is not allocated with any available instance, the Redis cluster stops receiving query requests. In this case, if some instances in the cluster are faulty (for example, some slots are not allocated), the entire cluster is unavailable. Once all slots are allocated, the cluster automatically becomes available.

yes

  • yes
  • no

maxmemory

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

1024

1 to 1048576

maxmemory-policy

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.

noeviction

  • volatile-lru
  • allkeys-lru
  • volatile-random
  • allkeys-random
  • volatile-ttl
  • allkeys-smart
  • volatile-smart
  • noeviction

rdbchecksum

Indicates whether to enable RDB verification. To prevent RDB persistent file errors, you are advised to enable RDB verification.

yes

  • yes
  • no

rdbcompression

Indicates whether to compress data when Redis performs RDB persistence.

yes

  • yes
  • no

stop-writes-on-bgsave-error

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

If this parameter is set to yes, Redis stops accepting write operations when an error occurs in the bgsave operation until the administrator manually rectifies the error.

yes

  • yes
  • no

activerehashing

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.

no

  • yes
  • no

activedefrag

Indicates whether to enable defragmentation.

If this parameter is set to yes, Redis automatically performs defragmentation when the memory usage exceeds the threshold to reduce memory fragments and improve memory utilization.

no

  • yes
  • no