Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis series-2, Redis configuration

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Redis configuration

There is a configuration file (redis.conf) in Redis that can be found in the root directory of Redis. You can set the configuration of all Redis through the CONFIG command of Redis.

2. Configuration file description:

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

Daemonize no

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

Pidfile / var/run/redis.pid

3. Specify the Redis listening port, and the default port is 6379. In a blog post, the author explains why 6379 is chosen as the default port, because 6379 has the number corresponding to MERZ on the phone button, and MERZ is named after Italian singer Alessia Merz.

Port 6379

4. Bound host address

Bind 127.0.0.1

5. When the client has been idle for how long, the connection is closed. If specified as 0, the function is disabled.

Timeout 300

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

Loglevel verbose

7. Logging method. Default is standard output. If Redis is configured to run in daemon mode, and here the logging mode is configured as standard output, the log will be sent to / dev/null.

Logfile stdout

8. Set the number of databases. The default database is 0. You can use the SELECT command to specify the database id on the connection.

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

Three conditions are provided in the Redis default configuration file:

Save 900 1

Save 300 10

Save 60 10000

It represents 1 change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds.

10. Specify whether to compress data when stored in the local database. The default is that yes,Redis uses LZF compression. If you want to save CPU time, you can turn this option off, but it will cause the database file to become huge.

Rdbcompression yes

11. Specifies the local database file name, which defaults to dump.rdb

Dbfilename dump.rdb

twelve。 Specify the local database storage directory

Dir. /

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

Slaveof

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

Masterauth

15. Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the AUTH command when connecting to the Redis. It is disabled by default.

Requirepass foobared

16. Set the maximum number of client connections at a time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that can be opened by Redis processes. If you set maxclients 0, there is no limit. 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 maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the expired or expiring Key. When this method is processed, the maximum memory setting will still be reached, and the write operation will no longer be performed, but the read operation can still be performed. Redis's new vm mechanism stores Key in memory and Value in swap area.

Maxmemory

18. Specifies whether to log after each update operation. Redis writes data to disk asynchronously by default. If it is not enabled, it may result in data loss for a period of time in the event of a power outage. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. Default is no

Appendonly no

19. Specify the update log file name. Default is appendonly.aof.

Appendfilename appendonly.aof

20. Specify the update log condition. There are 3 optional values:

No: indicates that the operating system synchronizes the data cache to disk (fast)

Always: means to manually call fsync () after each update operation to write data to disk (slow, secure)

Everysec: indicates synchronization once per second (eclectic, default)

Appendfsync everysec

21. Specify whether to enable the virtual memory mechanism. The default value is no. For a brief introduction, the VM mechanism stores the data in pages. Redis will swap the cold data on the disk, which is less visited, and the pages that visit more will be automatically swapped out to memory by the disk (I will carefully analyze the VM mechanism of Redis in a later article).

Vm-enabled no

twenty-two。 Virtual memory file path. Default is / tmp/redis.swap, which cannot be shared by multiple Redis instances.

Vm-swap-file / tmp/redis.swap

23. All data larger than vm-max-memory is stored in virtual memory, no matter how small the vm-max-memory setting is, all index data is stored in memory (Redis's index data is keys), that is, when vm-max-memory is set to 0, all value actually exists on disk. Default value is 0

Vm-max-memory 0

24. Redis swap files are divided into many page. An object can be stored on multiple page, but a page cannot be shared by multiple objects. Vm-page-size should be set according to the size of the stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64bytes. If large objects are stored, a larger page can be used. If you are not sure, use the default value.

Vm-page-size 32

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

Vm-pages 134217728

twenty-six。 Set the number of threads to access 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 long delay. The default value is 4

Vm-max-threads 4

twenty-seven。 Sets whether to merge smaller packets into a single packet when replying to the client. Default is on.

Glueoutputbuf yes

twenty-eight。 Specifies that a special hash algorithm is used when the number of elements exceeds a certain number or the largest element exceeds a critical value.

Hash-max-zipmap-entries 64

Hash-max-zipmap-value 512

twenty-nine。 Specifies whether to activate reset hashing, which is enabled by default (more on later when introducing Redis's hashing algorithm)

Activerehashing yes

thirty。 Specify to include other profiles that can use the same profile between multiple Redis instances on the same host, while each instance has its own specific profile

Include / path/to/local.conf

3. Grammar

The basic syntax of the CONFIG command for Redis is as follows:

Redis 127.0.0.1 redis 6379 > CONFIG GET CONFIG_SETTING_NAME for example redis 127.0.0.1 redis 6379 > CONFIG GET loglevel1) "loglevel" 2) "notice"

Let all configurations use * instead of CONFIG_SETTING_NAME

Example redis 127.0.0.1 requirepass * 1) "dbfilename" 2) "dump.rdb" 3) "requirepass" 4) "5)" masterauth "6)" 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 ) "list-max-ziplist-value" 32) "64" 33) "set-max-intset-entries" 34) "512" 35) "zset-max-ziplist-entries" 36) "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)" 12849) "port" 50) "6379" 51) "tcp-backlog" 52) "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)" 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" 1010) "appendfsync" 102) "everysec" 103) "save" 104) "3600 1 300 100 60 10000" 105) "loglevel" 106) Notice) "client-output-buffer-limit" 268435456) "normal 000 slave 268435456 67108864 60 pubsub 33554432 8388608 60" 109) "unixsocketperm" 110) "0111)" slaveof "112)"113C" notify-keyspace-events "114)" 115) "bind" 116) "4. Edit configuration

To update the configuration, you can edit the redis.conf file directly or update the configuration through the CONFIG set command

Grammar

The basic syntax of the CONFIG SET command is as follows:

Redis 127.0.0.1 redis 6379 > CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE example redis 127.0.0.1 redis 6379 > CONFIG SET loglevel "notice" OKredis 127.0.0.1 redis > CONFIG GET loglevel1) "loglevel" 2) "notice"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report