Latest web development tutorials

Redis configuration

Redis Redis configuration file located in the installation directory under the file name redis.conf.

You canCONFIG command to view or set the configuration items.


grammar

Redis CONFIG command format is as follows:

redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME

Examples

redis 127.0.0.1:6379> CONFIG GET loglevel

1) "loglevel"
2) "notice"

Press * to get all configuration items:

Examples

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 Configuration

You can modify redis.conf file or use theCONFIG set command to modify the configuration.

grammar

CONFIG SET command basic syntax:

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

Examples

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

1) "loglevel"
2) "notice"

Parameter Description

redis.conf configuration items are described below:

1. Redis default is not running in daemon mode, you can modify the configuration item, use yes Enable daemon

daemonize no

2. When Redis when running in daemon mode, the default Redis will write /var/run/redis.pid pid file, you can specify pidfile

pidfile /var/run/redis.pid

3. Specify Redis monitor port, the default port of 6379, the author in his own blog post explains why the choice of 6379 as the default port as 6379 on the phone keypad MERZ corresponding number, and MERZ taken from the name of Italian showgirl Alessia Merz

port 6379

4. The host address binding

bind 127.0.0.1

5. When the client is idle long after closing the connection, if you specify zero disables the function

timeout 300

6. Specify the logging level, Redis supports a total of four levels: debug, verbose, notice, warning, the default is verbose

loglevel verbose

7. logging mode, the default is standard output, if you configure Redis to run in daemon mode, but this is also configured for logging to standard output mode, the log will be sent to / dev / null

    logfile stdout

8. Set the number of the database, the default database is 0, you can use the SELECT <dbid> command on the connection specified database id

databases 16

9. Specify how long, how many times the update operation, the data will be synchronized to the data file, you can meet a number of conditions

save <seconds> <changes>

Redis default configuration file provides three conditions:

save 900 1

save 300 10

save 60 10000

Respectively, have a change 900 seconds (15 minutes), 300 seconds (5 minutes), there are 10 changes, and there are 10 000 Change in 60 seconds.

10. Is compression when storing data to a local database, the default is yes, Redis using LZF compression, if the CPU in order to save time, you can turn this option off, but will cause the database file becomes huge

rdbcompression yes

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

dbfilename dump.rdb

12. Specify local database storage directory

dir ./

13. Set when the unit is slav service, set master service IP address and port when Redis starts, it will automatically synchronize the data from the master

slaveof <masterip> <masterport>

14. When the master service is password-protected, slav service connection master password

masterauth <master-password>

15. Set Redis connection password, if you configure the connection password, the client needs to provide the password when connecting Redis via AUTH <password> command, off by default

requirepass foobared

16. Set the same time the maximum number of client connections, the default limit, the maximum number of file descriptors client connections Redis Redis can be open simultaneously for the process can be opened, if set maxclients 0, indicates no restrictions. When the number of client connections reaches the limit, Redis will close a new connection to the client returns the max number of clients reached an error message

maxclients 128

17. Specify Redis maximum memory limit, Redis will be loaded at startup data into memory, after the maximum memory, Redis will first try to clear Key has expired or about to expire, when this method worked, still reach the maximum memory settings will no longer write operations, but can still be read. Redis new vm mechanism, Key will be stored memory, Value will be stored in the swap area

maxmemory <bytes>

18. Specify whether or after each update operation logging, Redis default is asynchronous to write data to disk, if not open, it may result in data over time lost during a power outage. Because redis itself synchronize data files are synchronized by the above save conditions, so some data over a period of time exists only in memory. The default is no

appendonly no

19. Specify the update log file name, the default is appendonly.aof

appendfilename appendonly.aof

20. Specify the update log criteria, there are three possible values:
no: indicates the operating system and other data synced to disk cache (fast)
always: after every operation indicates the update manually call fsync () writes data to disk (slower, security)
everysec: represents a second synchronous (compromise, the default value)

appendfsync everysec

21. Specify whether the virtual memory mechanism is enabled, the default is no, a brief look, VM paging mechanism to store data by Redis will visit less-page C13 swap data to disk, the disk access multiple pages automatically swapped out to the memory (in a later article I will carefully analyze the Redis VM mechanism)

vm-enabled no

22. The virtual memory file path, the default value /tmp/redis.swap, can not share multiple instances of Redis

vm-swap-file /tmp/redis.swap

23. In all more than vm-max-memory data into virtual memory, regardless vm-max-memory settings how small, all index data is stored in memory (Redis index data is keys), that is, when vm -max-memory is set to 0 when the value is actually all are present in the disk. The default value is 0

vm-max-memory 0

24. Redis swap file into a lot of page, an object can be stored in multiple page above, but can not be shared by multiple objects on a page, vm-page-size is to be based on the stored data set size, the authors If you store a lot of recommendations for small objects, page size is preferably set to 32 or 64bytes; if the storage lot large objects, you can use a larger page, if you are unsure, use the default values

vm-page-size 32

25. The number of swap file page, since the page table (page idle or a representation using bitmap) is placed in memory on the disk ,, every eight pages 1byte will consume memory.

vm-pages 134217728

26. Set the number of threads to access the swap file, it is best not to exceed the number of core machine, if set to 0, then all operations on the swap file is serial, it may cause relatively long delays. The default value is 4

vm-max-threads 4

27. set when the response to the client, whether the smaller packets into one package, is enabled by default

glueoutputbuf yes

28. specified when more than a certain amount, or the largest element exceeds a critical value, using a special hash algorithm

hash-max-zipmap-entries 64

hash-max-zipmap-value 512

29. Specify whether to reset the activation hash, is enabled by default (specifically described later when the hashing algorithm described Redis)

activerehashing yes

30. Specifies that contains other configuration files, you can use the same configuration files between multiple Redis instances on the same host, while each instance has its own specific profile

include /path/to/local.conf