Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Redis configuration


May 16, 2021 Redis


Table of contents


Redis configuration

Redis' profile is located in the Redis installation directory and the file name is redis.conf.

You can view or set up configuration items through the CONFIG command.


Grammar

The Redis CONFIG command format is as follows:

redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME

Instance

redis 127.0.0.1:6379> CONFIG GET loglevel

1) "loglevel"
2) "notice"

Get * configuration items using the number:

Instance

redis 127.0.0.1:6379> CONFIG GET *

  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"
  8) ""
  9) "logfile"
 10) ""
 11) "pidfile"
 12) "/var/run/redis.pid"
 13) "maxmemory"
 14) "0"
 15) "maxmemory-samples"
 16) "3"
 17) "timeout"
 18) "0"
 19) "tcp-keepalive"
 20) "0"
 21) "auto-aof-rewrite-percentage"
 22) "100"
 23) "auto-aof-rewrite-min-size"
 24) "67108864"
 25) "hash-max-ziplist-entries"
 26) "512"
 27) "hash-max-ziplist-value"
 28) "64"
 29) "list-max-ziplist-entries"
 30) "512"
 31) "list-max-ziplist-value"
 32) "64"
 33) "set-max-intset-entries"
 34) "512"
 35) "zset-max-ziplist-entries"
 36) "128"
 37) "zset-max-ziplist-value"
 38) "64"
 39) "hll-sparse-max-bytes"
 40) "3000"
 41) "lua-time-limit"
 42) "5000"
 43) "slowlog-log-slower-than"
 44) "10000"
 45) "latency-monitor-threshold"
 46) "0"
 47) "slowlog-max-len"
 48) "128"
 49) "port"
 50) "6379"
 51) "tcp-backlog"
 52) "511"
 53) "databases"
 54) "16"
 55) "repl-ping-slave-period"
 56) "10"
 57) "repl-timeout"
 58) "60"
 59) "repl-backlog-size"
 60) "1048576"
 61) "repl-backlog-ttl"
 62) "3600"
 63) "maxclients"
 64) "4064"
 65) "watchdog-period"
 66) "0"
 67) "slave-priority"
 68) "100"
 69) "min-slaves-to-write"
 70) "0"
 71) "min-slaves-max-lag"
 72) "10"
 73) "hz"
 74) "10"
 75) "no-appendfsync-on-rewrite"
 76) "no"
 77) "slave-serve-stale-data"
 78) "yes"
 79) "slave-read-only"
 80) "yes"
 81) "stop-writes-on-bgsave-error"
 82) "yes"
 83) "daemonize"
 84) "no"
 85) "rdbcompression"
 86) "yes"
 87) "rdbchecksum"
 88) "yes"
 89) "activerehashing"
 90) "yes"
 91) "repl-disable-tcp-nodelay"
 92) "no"
 93) "aof-rewrite-incremental-fsync"
 94) "yes"
 95) "appendonly"
 96) "no"
 97) "dir"
 98) "/home/deepak/Downloads/redis-2.8.13/src"
 99) "maxmemory-policy"
100) "volatile-lru"
101) "appendfsync"
102) "everysec"
103) "save"
104) "3600 1 300 100 60 10000"
105) "loglevel"
106) "notice"
107) "client-output-buffer-limit"
108) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
109) "unixsocketperm"
110) "0"
111) "slaveof"
112) ""
113) "notify-keyspace-events"
114) ""
115) "bind"
116) ""

Edit the configuration

You can modify the configuration by modifying the redis.conf file or by using the CONFIG set command.

Grammar

ConfIG SET command basic syntax:

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

Instance

redis 127.0.0.1:6379> CONFIG SET loglevel "notice"
OK
redis 127.0.0.1:6379> CONFIG GET loglevel

1) "loglevel"
2) "notice"

Description of the parameters

The redis.conf configuration items are described below:

1. Redis does not run as a daemon by default, and can be modified with this configuration item, using yes to enable daemons

daemonize no

2. When Redis runs as a daemon, Redis writes the pid/var/run/redis.pid file by default, which can be specified by pidfile

pidfile /var/run/redis.pid

3. Specify the Redis listening port, the default port is 6379, the author explained in his own blog post why 6379 was chosen as the default port, because 6379 on the phone button MERZ corresponding number, and MERZ from the Italian singer Alessia Merz's name

port 6379

4. The host address of the binding

bind 127.0.0.1

5. When the client is idle for how long after the connection is closed, if specified as 0, the function is turned off

timeout 300

6. Specify the logging level, and Redis supports a total of four levels: debug, verbose, notice, warning, which defaults to verbose

loglevel verbose

7. Logging mode, which defaults to standard output, will be sent to /dev/null if Redis is configured to run as a daemon and logging is configured as standard output here

logfile stdout

8. Set the number of databases, the default database is 0, and you can specify the database id on the connection using the SELECT and lt;dbid> command

databases 16

9. Specify how long and how many update operations will synchronize the data to the data file, which can be matched by multiple conditions

save <seconds> <changes>

There are three conditions available in the Redis default profile:

save 900 1

save 300 10

save 60 10000

Represents 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes) and 10,000 changes in 60 seconds.

10. Specify whether to compress the data when storing to the local database, the default is yes, Redis uses LZF compression, if in order to save CPU time, you can turn off this option, but will cause the database file to become huge

rdbcompression yes

11. Specify the local database file name, with a default value of dump.rdb

dbfilename dump.rdb

12. Specify the local database to hold the directory

dir ./

13. Set the IP address and port of the master service when the machine is a slav service, and automatically synchronize the data from the master when Redis starts

slaveof <masterip> <masterport>

14. When the master service is password protected, the slav service connects to the master's password

masterauth <master-password>

15. Set the Redis connection password, and if the connection password is configured, the client needs to provide the password via the AUTOS command when connecting to Redis, which is turned off by default

requirepass foobared

16. Set the maximum number of client connections at the same time, with no limit by default, and the maximum number of client connections that Redis can open at the same time is the maximum number of file descriptors that the Redis process can open, which means no limit if maxclients 0 is set. When the number of client connections reaches the limit, Redis closes the new connection and returns a max number of clients reached error message to the client

maxclients 128

17. Specify the Redis maximum memory limit, where Redis loads data into memory at startup and reaches the maximum memory, Redis will first attempt to clear Key that has expired or is about to expire, and when this method is processed, the maximum memory setting will still be reached and no more writes will be available, but read operations will still be available. Redis' new vm mechanism stores Key in memory and Value in the swap area

maxmemory <bytes>

18. Specify whether to log after each update operation, and Redis writes data to disk asynchronously by default, which, if not turned on, can result in data loss for a period of time in the event of a power outage. B ecause the redis itself syncs data files according to the save conditions above, some data will only exist in memory for a period of time. The default is no

appendonly no

19. Specify the update log file name, which defaults to appendonly.aof

appendfilename appendonly.aof

20. Specify the update log conditions, which have three optional values:
No: indicates that the operating system is waiting for the data cache to sync to disk (fast)
always : indicates that fsync() is manually called after each update operation to write data to disk (slow, secure)
everysec: means synchronization every second (compromise, default)

appendfsync everysec

21. Specify whether to enable the virtual memory mechanism, the default value is no, a brief introduction, the VM mechanism will be paged data storage, by Redis will be less accessible pages that are cold data swap to disk, access to many pages from disk automatically swap out into memory (in the later article I will carefully analyze Redis VM mechanism)

vm-enabled no

22. Virtual memory file path, the default value is /tmp/redis.swap, not shared by multiple Redis instances

vm-swap-file /tmp/redis.swap

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

vm-max-memory 0

24. Redis swap files are divided into a lot of page, an object can be saved on more than one page, but a page can not be shared by more than one object, vm-page-size is based on the size of the stored data to set, the author suggests that if you store many small objects, page size is best set to 32 or 64bytes;

vm-page-size 32

25. Set the number of pages in the swap file, because the page table (a bitmap that indicates that the page is idle or used) is placed in memory, and every 8 pages on disk consumes 1 byte of memory.

vm-pages 134217728

26. Set the number of threads accessing the swap file, it is best not to exceed the number of cores of the machine, if set to 0, then all operations on the swap file are serial, which may cause a longer delay. The default is 4

vm-max-threads 4

27. Set whether smaller packages are combined to send as one package when answering clients, which is turned on by default

glueoutputbuf yes

28. Specifies that a special hash algorithm is used when a certain number or maximum element exceeds a critical value

hash-max-zipmap-entries 64

hash-max-zipmap-value 512

29. Specify whether to activate the reset hash, which is turned on by default (detailed later in the introduction of Redis' hash algorithm)

activerehashing yes

30. Specify that there are other profiles that can be used between multiple Redis instances on the same host, while each instance has its own specific profile

include /path/to/local.conf