Redis Database Configuration Parameters Detailed introduction

Source: Internet
Author: User
Tags allkeys compact lua redis time interval volatile strong password redis cluster

Redis configuration parameters, very much, the following list of some redis commonly used parameter configuration, as well as Chinese comments.


/********************************* General *********************************/
Whether to run as a daemon
Daemonize Yes

If the next stage of the process is running, you need to specify a PID, default is/var/run/redis.pid
Pidfile/var/run/redis.pid

Redis Default Listening port
Port 6379

Tcp-backlog 511

How many seconds the client is idle before disconnecting
Timeout 0

Tcp-keepalive 0

Logging level, with 4 optional values, debug,verbose,notice,warning
LogLevel Notice

Specifies the file name of the log output, which can be set to/dev/null screen log
LogFile ""

Number of available databases, default value is 16, default database is 0
Databases 16

/****************************** snapshotting Snapshot *********************************/
Strategies for saving data to disk
900 seconds with 1 changes saved to disk
Save 900 1
300 seconds with 10 changes saved to disk
Save 300 10
60 seconds with 10,000 changes saved to disk
Save 60 10000

Stop-writes-on-bgsave-error Yes

Whether to compress data objects when dump. Rdb Database
Rdbcompression Yes

Rdbchecksum Yes

Local database filename, default value is Dump.rdb
Dbfilename Dump.rdb

The local database holds the path, and the default value is./
Dir./

Replication configuration for/*************************** REPLICATION Redis *********************************/

Set the IP and port of the primary service when this machine is from service
Slaveof <masterip> <masterport>

Set the connection password for the primary service when this computer is from service
Masterauth <master-password>

When a connection is lost from the library or replication is in progress, there are two ways to run from the hangar
1 if Slave-serve-stale-data is set to Yes (the default setting), requests from the library for the corresponding client will continue
2 if slave-serve-stale-data refers to no, any request outside the info and SLAVOF commands will return an error "SYNC with Master in progress"
Slave-serve-stale-data Yes

Slave-read-only Yes

Repl-diskless-sync No

Repl-diskless-sync-delay 5

The pings is sent from the library at a time interval to the main library. You can set this time interval by repl-ping-slave-period, and the default is 10 seconds.
Repl-ping-slave-period 10

Repl-timeout set the main library bulk data transfer time or ping reply interval, the default value is 60 seconds
Make sure Repl-timeout is larger than repl-ping-slave-period
Repl-timeout 60

Use no delay synchronization default No
Repl-disable-tcp-nodelay Yes

Slave-priority 100

/********************************* Security *********************************/

Set the password that you want to use before any other designation is made after the client connects.
Warning: Because the Redis speed is very fast, so in a better server, an external user can do a 150K password attempt in a second,
Which means you need to specify a very, very strong password to prevent brute force cracking.
Requirepass foobared

Command Rename.
You can rename a relatively dangerous command in a shared environment. For example, rename the config to a character that is not easily guessed.
Example:
Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
If you want to delete a command, simply rename it to a null character "", as follows:
Rename-command CONFIG ""

/********************************* LIMITS Constraint *********************************/
Maximum available memory maxmemory <bytes> 536870912, or 512M
MaxMemory 536870912

What data will redis choose to delete when memory reaches its maximum value? There are five different ways to choose
//
VOLATILE-LRU-> uses LRU algorithm to remove keys that have set expiration times (LRU: Recent use least recently)
ALLKEYS-LRU-> use LRU algorithm to remove any key
Volatile-random-> removes a random key that has set an expiration time
Allkeys->random-> Remove a random key, any key
Volatile-ttl-> Remove the Expiring key (minor TTL)
Noeviction-> not remove any can, just return a write error
Maxmemory-policy ALLKEYS-LRU

LRU and minimal TTL algorithms are not accurate algorithms, but relatively accurate algorithms (to save memory), you can choose the sample size to detect.
Redis default Gray selection of 3 samples for detection, you can set up by maxmemory-samples
Maxmemory-samples 3

/********************************* APPEND only MODE *********************************/

Enable AOF persistence mode
Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. The default value is no
AppendOnly Yes

Update log file name, default value is Appendonly.aof
Appendfilename "Appendonly.aof"

Write commands are written to disk immediately, slowest, guaranteed to be fully persisted
Appendfsync always
Write once per second
Appendfsync everysec
Fully dependent on OS, best performance, no guarantee of persistence
Appendfsync No

Deploy the Redis instance of the same machine, turn the auto-aof-rewrite on, because the memory footprint in the cluster environment is basically consistent
Fsync the new write operation when #关闭在aof rewrite
No-appendfsync-on-rewrite Yes

Automatic rewrite of the append only file.
AOF Auto Rewrite
When the aof file grows to a certain size Redis can invoke bgrewriteaof to rewrite the log file
//
It works like this: Redis remembers the size of the file after the last log (if it hasn't been rewritten since it was turned on, the size of the day is determined when the boot is on)
//
The base size is compared with the current size. If the current size is larger than the base size, the override feature will start
At the same time, you need to specify a minimum size for the AOF rewrite, which is used to block the AoF file if the file is small but grows very large
Set percentage to 0 to turn off this feature
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB

aof-load-truncated Yes

/********************************* LUA Scripting *********************************/
Lua-time-limit 5000

/********************************* redis CLUSTER Cluster *********************************/
Open Redis Cluster
cluster-enabled Yes

Cluster configuration file (start automatic generation)
Cluster-config-file nodes-6379.conf

Valve Value for node interconnect timeout
Cluster-node-timeout 15000

//
Cluster-slave-validity-factor 10

//
Cluster-migration-barrier 1

Cluster compatibility partial failure
Cluster-require-full-coverage Yes

/********************************* Slow LOG *********************************/

Redis slow log records commands that exceed a specific execution time. Execution time does not include I/O calculations, such as connecting clients, returning results, and so on, only the command execution time
//
Slow log can be set with two parameters: one is to tell the Redis to execute more than how much time is recorded for the parameter Slowlog-log-slower-than (subtle),
The other is the length of the slow log. The oldest command is removed from the queue when a new command is logged

The following time with subtle micro units, so 1000000 represents a minute.
Note that setting a negative number will turn off the slow log, and a set of 0 will force each command to record
Slowlog-log-slower-than 10000

There is no limit to the length of the log, just be aware that it consumes memory
Memory that is consumed by slow logging can be reclaimed by Slowlog RESET
Slowlog-max-len 128

/********************************* Latency MONITOR *********************************/

Latency-monitor-threshold 0

/********************************* EVENT NOTIFICATION *********************************/

Notify-keyspace-events ""

/********************************* ADVANCED CONFIG *********************************/

When the hash contains more than the specified number of elements and the largest element does not exceed the critical
The hash will be stored in a special encoding (greatly reducing memory usage), where these two thresholds can be set
Redis hash corresponds to the value inside the actual is a hashmap, in fact there will be 2 different implementations,
This hash is a relatively young member Redis in order to save memory by using a one-dimensional array of methods to compact storage,
Instead of using a real HASHMAP structure, the corresponding value Redisobject encoding is Zipmap,

When the number of members increases, it automatically turns into a real hashmap, at which point encoding is HT.

Hash-max-ziplist-entries 512
Hash-max-ziplist-value 64

The number of nodes in the list data type follows the compact storage format of the pointer.
The list data type node value size less than how many bytes will be in a compact storage format.
List-max-ziplist-entries 512
List-max-ziplist-value 64

Set data type internal data if all are numeric, and how many nodes are included, the following will be stored in compact format.
Set-max-intset-entries 512

Zsort data type How many nodes below will take the compact storage format of the pointer.
Zsort data type node value size less than how many bytes will be in a compact storage format.
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64

Hll-sparse-max-bytes 3000

Redis will use 1 milliseconds of CPU time per 100 milliseconds to hash the Redis hash table to reduce memory usage
//
When you have a very stringent real-time requirement in your usage scenario, you cannot accept Redis's 2 millisecond delay to the request, and configure this to No.
//
If you do not have such stringent real-time requirements, you can set to Yes so that you can free up memory as quickly as possible
activerehashing Yes

Client-output-buffer-limit Normal 0 0 0
Client-output-buffer-limit slave 256MB 64MB 60
Client-output-buffer-limit pubsub 32MB 8MB 60

Hz 10

Aof-rewrite-incremental-fsync Yes

/********************************* VM *********************************/

Whether to use virtual memory, the default value is no
vm-enabled Yes

Virtual memory file path, default value is/tmp/redis.swap, not multiple Redis instance sharing
Vm-swap-file/tmp/redis.swap

Store all data larger than vm-max-memory into virtual memory, regardless of how small the vm-max-memory setting is, all index data is memory-stored
(The Redis index data is the keys), that is, when Vm-max-memory is set to 0, all of the value is in the disk. The default value is 0.
Vm-max-memory 0

Virtual memory files are stored in blocks, 32bytes per block
Vm-page-size 32

Maximum number of virtual internal files
Vm-pages 134217728

You can set the number of threads to access the swap file, setting the best not to exceed the machine's kernel number, and if set to 0, all operations on the swap file are serial.
May result in a longer delay, but there is a good guarantee of data integrity.
Vm-max-threads 4

/********************************* INCLUDES *********************************/
Contains generic configurations
Include/etc/redis/redis-common.conf

/********************************* General *********************************/
If the next stage of the process is running, you need to specify a PID, default is/var/run/redis.pid
Pidfile/var/run/redis_6379.pid

Redis Default Listening port
Port 6379

Specifies the file name of the log output, which can be set to/dev/null screen log
Logfile/var/log/redis_6379.log

/********************************* snapshotting Snapshot *********************************/

Local database filename, default value is Dump.rdb
Dbfilename Dump6379.rdb

The local database holds the path, and the default value is./
dir/var/redis/6379

Replication configuration for/********************************* REPLICATION Redis *********************************/

Set the IP and port of the primary service when this machine is from service
Slaveof <masterip> <masterport>

Set the connection password for the primary service when this computer is from service
Masterauth <master-password>

/********************************* APPEND only MODE *********************************/

Update log file name, default value is Appendonly.aof
Appendfilename "Appendonly6379.aof"

/********************************* redis CLUSTER Cluster *********************************/

Cluster configuration file (start automatic generation)
Cluster-config-file nodes-6379.conf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.