Redis configuration file in a detailed

Source: Internet
Author: User
Tags allkeys

Redis configuration file redis.conf detailed

1. Basic Configuration

Representation of memory units

# 1k = bytes
# 1kb = 1024x768 bytes
# 1m = 1000000 bytes
# 1MB = 1024*1024 bytes
# 1g = 1000000000 bytes
# 1GB = 1024*1024*1024 bytes

Case insensitive 1GB 1Gb 1gB is the same in a unit

Background run, yes background run, no foreground run, output, output to terminal (default)

Daemonize Yes

If the daemonize parameter is yes, the PID file will be generated, which is the definition of the PID file.

Pidfile/usr/local/redis-master/run/redis.pid

Ports to listen on

Port 6379

IP address of the binding listener

Bind 127.0.0.1

If you call Redis locally, you can use the sock file directly

Unixsocket/tmp/redis.sock the location of the//sock file

Unixsocketperm permissions for 755//sock files

If a link is idle within n seconds, it is closed

Timeout 0

If the other side is down or the middle network is off, sending an ACK to the client to disconnect the TCP link (in seconds) without receiving a response within a specified time, this parameter is affected by the kernel parameters and is recommended for configuration 60.

Tcp-keepalive 0

Specify the level of the output message

# debug (Debug level, details, large amount of information)
# verbose (more info, larger information)
# Notice (notification, production environment recommended)
# Warning (Error message warning message)

LogLevel Notice

Log output file, the default value of this key when running at the front end is the stdout output to the terminal, if you use the daemon to run this key stdout the log input to/dev/null, if you want to log, you must specify the logfile location

Logfile/var/log/redis.log

Log-Logged Oh syslog

Syslog-enabled No

Specify the identity of the syslog

Syslog-ident Redis

Specifies the level of the syslog, which must be between LOCAL0-LOCAL7

Syslog-facility local0

Set the number of databases

Databases 16

Set the number of databases. Default DB 0, you can choose a different per-connection to use select<dbid> here's dbid is a between 0 and ' databases '-1

Databases 16

2. Snapshot configuration

Rule definition (snapshot) for saving db to disk

Format: Save <seconds> <changes>

Example: Save 900 1//within 900 seconds (15 minutes) if at least 1 key values change

Save 300 10//within 300 seconds (6 minutes) if at least 10 key values change
Save 900 1//each bar represents a deposit count
Save 300 10
Save 60 10000

If you enable the snapshot above (RDB), the Redis will still work after a storage count, possibly the disk will be broken or the permissions problem

Stop-writes-on-bgsave-error Yes

Whether to compress the string into the. Rdb database with LZF, if you want to conserve CPU resources can be set to No, but the string stored on disk occupies a large space, the default is Yes

Rdbcompression Yes

RDB file verification, if the checksum will avoid the file format is broken, if not the checksum will be paid each time the file to pay the verification process of the new energy, set this parameter to no, the checksum will be skipped

Rdbchecksum Yes

File name of the dump data

Dbfilename Dump.rdb

Redis's working directory, which stores the dump file in this directory and generates an additional file

dir/usr/local/redis-master/db

3. Master and Slave parameters
If the local is a salve server then configure the item

# slaveof <masterip> <masterport>

slaveof 127.0.0.1 65532

Authentication password for Master

Masterauth <master-password>

When the link from the host is detached from the master, if this value is yes when the client queries from, the client is echoed, if it is the first time the synchronization returns a date data or this null value, if set to No, then return "SYNC with Master in progress" to info and slaveof

Slave-serve-stale-data Yes

Read-only from server (default)

Slave-read-only Yes

Interval from ping to main (in seconds)

Repl-ping-slave-period 10

Bulk transfer I/O timeout and master data or ping response timeout default 60s must be greater than Repl-ping-slave-period value

Repl-timeout 60

If this option is "yes" then Redis uses a smaller number of TCP packets and less bandwidth to send the data to, with a delay of 40 milliseconds (40 milliseconds in Linux kernel) from the host. If no will reduce the delay in slave, but the traffic is used back relatively more, if more than one from the host, here is recommended to set to Yes

Repl-disable-tcp-nodelay No

From the host's priority, if when the master is hung up, it will pick one from the host as the master of the other slave, the lowest priority number will become the primary, 0 is a special level, and 0 will never be the master. The default value is 100.

Slave-priority 100

4. Security Configuration
Password on this machine, if someone asks for a link that needs its verification

Requirepass Password

Command rename if the change command may have a problem from the server

Example: Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52// Name the config command as b840fc02d524045429941cc15f59e41cb7be6c52

Rename-command CONFIG ""//Default is empty

5. Limits
Maximum number of client links

MaxClients 10000

Maximum memory usage If it is a master-slave, this value should be set to a lower

MaxMemory <bytes>

How to remove k&y when Redias reaches MaxMemory

Volatile-lru. Remove expired key values with the LRU algorithm

Allkeys-lru. Remove all key values with the LRU algorithm

Volatile-random, delete expired key values randomly

Allkeys-random, randomly delete any key value

Volatile-ttl---delete the most recent key value to expire (monitor TTL)

Noeviction, no write operation, returns an error

At the date of writing this commands Are:set setnx setex append incr decr rpush lpush rpushx lpushx linsert LSet Rpoplpus h sadd sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincr by Incrby Decrby getset mset msetnx exec sort

The default value example is as follows:

Maxmemory-policy VOLATILE-LRU


LRU and the minimum TTL algorithm are inaccurate, pick several in a few to check the recent use of the minimum key value to delete, in order to save memory can be set small point.

Maxmemory-samples 3


6.append only

Enabling aof and RDB persistence, if one or more write points are lost in the time between the write point and the write point, and if this attribute is enabled, Redis writes the value of add to the attached file, which is enabled by default.

AppendOnly No

filename of the Oaf file

Appendfilename appendonly.aof

The Append only file name is defined by the Appendfilename appendonly.aof entry, and there are three ways to redias the data as soon as it is in the AoF file:

No: Let the OS refresh the data quickly

Always: Call function Fsync after each write to write the most secure

Everysec: Every second to call Fsync to write

Default value: Appendfsync everysec


If the disk performance problem is slow, set it to Yes, and the disk I/O is more secure than the no data.

No-appendfsync-on-rewrite No


Write rules for oaf files

As follows: Stop writing if you reach 100% of 64M

Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB


7.LUA SCRIPTING
Maximum time to execute a LUA script, prevent dead loops, etc., set to 0 is no limit, in seconds

Lua-time-limit 5000


Slow query record for 8.redias
If the execution command that is greater than the following value is logged, the default is 10000, the unit is subtle (1000000 microseconds = = 1 seconds), set to a negative number when the police use this record, set to 0 o'clock, record any execution command

Slowlog-log-slower-than 10000


The size of this value affects the size of the memory, and the recycled memory can be used Slowlogreset

Slowlog-max-len 128


9. Advanced Configuration
Entry thresholds for hash encodings using high-speed memory data structures

If the type member value of Redisobject is Redis_list, the number of Elem for the LIST is less than the configured value: the length of the hash-max-ziplist-entries or elem_value string is less than Hash-max-ziplist-value, it can be encoded into Redis_encoding_ziplist type storage to conserve memory. Otherwise use Dict to store.


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

A list of the same hash values can be stored in a special way to save space and the thresholds are set as follows

If the type is redis_list, if its entry is less than the configured value: List-max-ziplist-entries or the value string is less than list-max-ziplist-value, it can be encoded as Redis_enc Oding_ziplist type storage to conserve memory; Otherwise use Redis_encoding_linkedlist to store


List-max-ziplist-entries 512
List-max-ziplist-value 64


# Sets has a special encoding in just one case:when a set is composed
# of just strings that happens to being integers in radix ten in the range
# of signed integers.
# The following configuration setting sets the limit in the size of the
# Set in order the use of this special memory saving encoding.

If the type is Redis_set, if its value can be expressed as a numeric type and entry is less than the configured value set-max-intset-entries, it can be encoded into a redis_encoding_intset type store to conserve memory; Otherwise, the Dict type is used to store
Set-max-intset-entries 512

In the same hash list, the elements and lengths of the sorted list cannot be higher than the following values

Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64


When rebuilding the hash table if there is not enough memory if this value is set to no then delay, if yes, free memory as soon as possible.

activerehashing Yes


Client buffer limit, disconnect immediately if hard limit is reached

Three types of clients

# Normal Client
# Slave from client or monitoring client
# PubSub Subscription or publishing client

The syntax for client throttling is as follows

Client-output-buffer-limit <class>

The default is as follows

Client-output-buffer-limit Normal 0 0 0
Client-output-buffer-limit slave 256MB 64mb//slave client buffer hard limit is 256M, soft limit is 64mb/60 seconds to disconnect
Client-output-buffer-limit pubsub 32MB 8MB 60

The number of CPUs a task can use

Hz 10


10. configuration file include
Example:

# include/path/to/local.conf
# include/path/to/other.conf

Redis configuration file in a detailed

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.