Redis configuration file detailed summary

One, redis.conf configuration file

1.daemonize no

By default, redis does not run in the background. If you need to run in the background, change the value of this item to yes;

2. pidfile /var/run/redis.pid

When redis is running in the background, Redis will put the pid file in /var/run/redis.pid by default, and you can configure it to other addresses. When running multiple redis services, you need to specify different pid files and ports.

3. port 6379

Specify the port on which redis runs

4. timeout 0

Set the timeout period when the client connects, in seconds. When the client does not issue any instructions within this period of time, the server closes the connection. 0 is turned off the setting.

5. loglevel notice

Server log level, legal values: debug, verbose, notice, warning The default is notice

Debug is suitable for development environment, and client operation information will output logs

verbose outputs some relatively useful information, and the effect is currently unknown

notice suitable for production environment

warning exception information

6.logfile

Specify the Redis log recording method, the default value is stdout, which means that it is printed on the command line terminal window, or it can be set to /dev/null to shield the log

7. maxclients 128

Limit the number of clients connected at the same time. When the number of connections exceeds this value, redis will no longer receive other connection requests, and the client will receive an error message when trying to connect

8. maxmemory <bytes>

Set the maximum memory that redis can use. After reaching the maximum memory settings, Redis will first try to clear expired or about to expire Key (set too expire information key) when you delete, delete in accordance with the expiration time, the first to be expired key will be the first to be deleted if If the key that has expired or is about to expire is deleted, and the set operation is still performed, an error will be returned. At this time, redis will no longer receive write requests, only get requests. The maxmemory setting is more suitable for using redis as a cache similar to memcached

9. maxmemory-policy

What data will Redis choose to delete when the memory reaches its maximum value? There are five ways to choose

volatile-lru -> Use the LRU algorithm to remove the key with an expiration time (LRU: Least Recently Used)

# allkeys-lru -> Use LRU algorithm to remove any key

# volatile-random -> Remove random keys with expiration time set

# allkeys->random -> remove a random key, any key

# volatile-ttl -> Remove the key that is about to expire (minor TTL)

# noeviction -> Do not remove anything, just return a write error

Note: For the above strategy, if there is no suitable key to remove, Redis will return an error when writing

Write commands include: set setnx setex append

# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd

# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby

# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby

# getset mset msetnx exec sort

The default is:

# maxmemory-policy volatile-lru


10. syslog-enabled no

'syslog-enabled' is set to yes to output the log to the system log, the default is no

11. syslog-facility local0

Specify the syslog facility (facility), which must be USER or LOCAL0 to LOCAL7


Two, SLOWLOG (log)

1. slowlog-log-slower-than 10000

Redis slow log is used to record queries that exceed the specified execution time. Execution time does not include the I / O connector such as the client computing, and so returns a result, only the command execution line time can be set slow log by two parameters: a parameter tells slowlog-log-slower-than how much time is recorded in the execution than Redis (ms), the other one is a slow log length. When a new command is recorded, the oldest command will be removed from the queue. Negative numbers will turn off the slow log. 0 will cause each command to be recorded.

2. slowlog-max-len

There is no limit to the length of the log, just be aware that it will consume memory. The memory consumed by the slow log can be recovered through SLOWLOG RESET


Three, advanced configuration

1. hash-max-zipmap-entries 512

hash-max-zipmap-value 64

The hash data structure was introduced after redis 2.0.

When the hash contains more than the specified number of elements and the largest element does not exceed the threshold,

# hash will be stored in a special encoding method (which greatly reduces memory usage), and these two critical values ​​can be set here

# Redis Hash对应Value内部实际就是一个HashMap,实际这里会有2种不同实现,

# 这个Hash的成员比较少时Redis为了节省内存会采用类似一维数组的方式来紧凑存储,而不会采用真正的HashMap结,对应的value redisObject的encoding为zipmap,

# 当成员数量增大时会自动转成真正的HashMap,此时encoding为ht。

2. activerehashing yes

是否重置Hash表设置成yes后redis将每100毫秒使用1毫秒CPU时间来对redis的hash表重新hash,可降低内存的使用,当使用场景有较为严格的实时性需求,不能接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。如果没有这么严格的实时性要求,可以设置为 yes,以便能够尽可能快的释放内存

3. list-max-ziplist-entries 512

list-max-ziplist-value 64

list 数据类型多少节点以下会采用去指针的紧凑存储格式。

list 数据类型节点值大小小于多少字节会采用紧凑存储格式。

4. set-max-intset-entries 512

set数据类型内部数据如果全部是数值型,且包含多少节点以下会采用紧凑格式存储。

5. zset-max-ziplist-entries 128

zset-max-ziplist-value 64

zsort 数据类型多少节点以下会采用去指针的紧凑存储格式。

zsort 数据类型节点值大小小于多少字节会采用紧凑存储格式。


四、Replication(复制)

1. slaveof

将当前server做为slave,并为其指定master信息.

slaveof <masterip> <masterport> 当本机为从服务时,设置主服务的IP及端口

# slaveof <masterip> <masterport>

slaveof 192.168.210.85  6379

2. masterauth

以认证的方式连接到master。如果master中使用了”密码保护”,slave必须交付正确的授权密码,才能连接成功。

“requirepass”配置项指定了当前server的密码。

此配置项中值需要和master机器的”requirepass”保持一致

 masterauth tinywanredis

redis在真实环境中不可以谁想访问就访问,所以,必须要设置密码,修改redis.conf文件配置 

# requirepass foobared去掉注释,foobared改为自己的密码。

3. slave-serve-stale-data yes

如果当前server是slave,那么当slave与master失去通讯时,是否继续为客户端提供服务,”yes”表示继续,”no”表示终止.

在”yes”情况下,slave继续向客户端提供只读服务,有可能此时的数据已经过期.

在”no”情况下,任何向此server发送的数据请求服务(包括客户端和此server的slave)都将被告知”error”,但 INFO 和SLAVEOF

命令除外。

# When a slave loses its connection with the master, or when the replication

# is still in progress, the slave can act in two different ways:slave-serve-stale-data yes


五、redis数据存储

redis的存储分为内存存储、磁盘存储和log文件三部分,配置文件中有三个参数对其进行配置。

save seconds updates,save配置,指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。可多个条件配合,默认配置了三个条件。

appendonly yes/no ,appendonly配置,指出是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面的save条件来同步的,所以有的数据会在一段时间内只存在于内存中。

appendfsync no/always/everysec ,appendfsync配置,no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次。


Guess you like

Origin blog.51cto.com/15127516/2657662