When playing Redis, often touch redis redis.conf configuration file, it is very useful, can configure a lot of functions, below I will detail the next redis.conf file content. redis.conf File Location
Units units
includes contains
General Universal
Daemonize Yes
Daemonize means: Run in the background.
If you do not configure to run in the background, you will not be able to deploy the cluster
Pidfile/var/run/redis.pid
Pipeline file configuration.
Port 6379
The default value,/var/run/redis.pid, specifies the process number file path for the Redis service, which you need to configure when running in daemon mode;
LogLevel Notice
Set the log level of the service side, there are several options (prompt details from top to bottom, tips less and fewer): Debug: Record details for development or debugging; verbose: Provide a lot of useful information, but not as detailed as debug, the default is this option; Notice: Moderate reminders, more for the product environment; Warning: Displays only important warning messages;
LogFile ""
Specifies the output path of the log, the default value of stdout, indicating output to the screen, background mode output to/dev/null;
If you want to output the log, you can set syslog-enabled Yes, the default option value is no, indicating that the log is not output.
Syslog-enabled
Whether to output the log.
Syslog-ident Redis
The log file name is identified.
Syslog-facility local0
Output Logging Tool
Databases 16
Specifies the number of databases, which defaults to 16, and the database used by default is DB 0.
Tcp-backlog 511
Setting the TCP Backlog,backlog is actually a connection queue, the backlog queue sum = Three handshake queue not completed + three handshake queue completed.
In high-concurrency environments you need a high backlog value to avoid slow client connectivity issues. Note that the Linux kernel will reduce this value to the/proc/sys/net/core/somaxconn value, so you need to confirm the increase of somaxconn and tcp_max_syn_backlog two values to achieve the desired effect.
In another word:
This parameter determines the length of the completed queue (after three handshake) in a TCP connection, which must not be less than the Linux system-defined/proc/sys/net/core/somaxconn value, which is 511 by default, and the default parameter value for Linux is 128. When the system concurrency is large and the client is slow, the two parameters can be referenced together. The default value for this kernel parameter is typically 128, which is not large enough for a heavily loaded service program. It is generally modified to be 2048 or larger. Add: Net.core.somaxconn = 2048 in/etc/sysctl.conf, then execute sysctl-p in the terminal.
Bind 127.0.0.1
Specifies that Redis receives only requests from that IP address, and if not set, all requests are processed
Timeout 0
This parameter sets the client to idle for more than timeout, the server disconnects, and for 0 the service side does not actively disconnect, not less than 0.
Tcp-keepalive 0
The TCP keepalive parameter. If the setting is not 0, Keepalive detection is not performed, the recommended setting is 60, and the official recommended value is 300S. There are two advantages to using the keepalive: Detecting a dead peer. The problem of reducing the problem of intermediate devices and causing the network to appear to be connected has been disconnected from the end. In the Linux kernel, the Keepalive,redis is set to send an ACK to the peer at timed intervals. Detects if the peer is off. snapshotting Snapshot
Save <seconds> <changes>
Indicates how many seconds the write operation will trigger an automatic memory data backup.
An RDB is a compressed Snapshot (snapshot) of the entire memory, an RDB data structure that can be configured with a composite snapshot trigger condition.
Default (recommended by default, this is the official best practice):
I changed it 1 times in 15 minutes.
I changed it 10 times in 5 minutes.
I changed it 10,000 times in 1 minutes.
So how to disable automatic backup snapshot ...
If you want to disable the policy for RDB persistence, simply do not set any save instructions or pass an empty string argument to save.
How to make important data fast backups.
Dynamic manual backups can be achieved by hitting save or Bgsave commands directly from the console.
Stop-writes-on-bgsave-error
Indicates whether to stop writing memory data if an error occurs while backing up memory data in the background.
If configured as no, you do not care about inconsistent data or other means of discovery and control.
The default is yes.
Rdbcompression Yes
Using the compressed Rdb file, the Rdb file compression uses the LZF compression algorithm, yes: compression, but requires some CPU consumption. No: No compression, requires more disk space.
It is recommended to use compression.
Rdbchecksum Yes
After storing the snapshot, you can also have Redis use the CRC64 algorithm for data validation. Starting with the fifth version of the RDB format, a CRC64 checksum is taken at the end of the Rdb file. This is good for file tolerance, but when you save an RDB file, you have about 10% performance loss, so if you're pursuing high performance, you can turn off the configuration.
Recommended to open ... REPLICATION Replication
Not to be continued ... Security Safety
Get the connection password and service startup path:
To modify the Redis connection password:
LIMITS Restrictions
MaxClients 10000
Set the maximum number of client connections that can connect to Redis. The default is 10,000 client connections. The MaxClients minimum recommendation is set to 32 because Redis does not differentiate between whether the connection is a client connection or an internal open file or a slave connection. If the Maxclients,redis is exceeded, the new connection is sent ' max number of clients reached ' and the connection is closed.
MaxMemory <bytes>
Maximum memory capacity of the Redis configuration. When the memory is full, you need to work with the Maxmemory-policy policy. Note that the output buffer of the slave is not calculated in MaxMemory. Therefore, to prevent the host memory from being used, the recommended maxmemory need to be smaller.
So, the question often asked is how Redis's memory strategy is configured.
Maxmemory-policy noeviction
Processing policy after the memory capacity exceeds maxmemory.
VOLATILE-LRU: Use the LRU (less recentely uses) algorithm to remove the most recently used key that has been set to expire for the last time.
Volatile-random: Randomly removes the key that set the expiration time.
Volatile-ttl: Remove expiring key and delete (with TTL) to save new data based on last expiration time
ALLKEYS-LRU: Prioritize deleting any key that is most infrequently used recently to save new data
Allkeys-random: Randomly select some key from the All-keys to delete it to save the new data.
Noeviction: Do not remove any key, just return a write error.
Above these eviction strategies, if Redis does not have the appropriate key evicted, it will return an error for the write command. Redis will no longer receive write requests and receive only get requests. Write commands include: Set setnx Setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd sinter sinterstore Sunion Sun ionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby getset mset msetnx exec sort.
Maxmemory-samples
Set the number of samples, the LRU algorithm and the minimum TTL algorithm are not accurate algorithms, but estimates, so you can set the size of the sample, Redis by default will check so many key and choose the one that LRU. APPEND only MODE append
AppendOnly No
The default Redis uses an RDB-style persistence, which is sufficient for many applications. But if Redis goes down, it can result in a few minutes of data loss, and a policy persistence based on save, Append only file is another way to persist, providing better persistence. Redis writes each written data to the Appendonly.aof file after it is received, and Redis reads the file's data into memory each time it is started, ignoring the Rdb file first.
Appendfilename "Appendonly.aof"
AOF file backup and the name of the data loaded into memory.
Appendfsync everysec
AOF file backup mode.
There are three modes: always: Asynchronous synchronous persistence every time a data change occurs, it is immediately logged to disk performance is poor but data integrity is better. EVERYSEC: Factory default recommendation, asynchronous operation, record per second, if the outage within one second, there is a second data loss. No: Indicates that the fsync is not executed and the operating system guarantees that the data is synchronized to disk at the fastest speed.
No-appendfsync-on-rewrite No
When the aof rewrite or append to the AoF file, it executes a lot of Io, at this time, for everysec and always aof mode, the execution of Fsync will cause blocking too long, The No-appendfsync-on-rewrite field is set to No by default. This field can be set to Yes if there is a high latency requirement, or it is set to No, which is a more secure option for persistent features. Set to Yes indicates that the new write operation is not fsync during rewrite, is temporarily present in memory, and so on, and so on rewrite completion, the default is no, recommended yes. The default Fsync policy for Linux is 30 seconds. Data may be lost for 30 seconds.
Auto-aof-rewrite-percentage 100
AOF automatically overrides the configuration. When the current aof file size exceeds the AoF file size of the last rewrite, it is rewritten that Redis can call bgrewriteaof to rewrite the log file when the AoF file grows to a certain size. The current aof file size is twice times the size of the AoF file when the last log rewrite (set to 100) automatically starts a new log rewrite process.
Auto-aof-rewrite-min-size 64MB
Sets the minimum aof file size that is allowed to be overridden, avoiding cases where the agreed percentage is reached but the size is still small.
If it is a better company, this value 3G is set to start, but usually large-scale applications here are set to 6G,
When you see that the value of your company is 64MB, you will be able to know the level of the company. Common Configuration redis.conf Introduction
Not to be continued ...