Home  >  Article  >  Database  >  How to configure redis

How to configure redis

尚
Original
2019-07-05 14:57:094561browse

How to configure redis

The Redis configuration file is located in the Redis installation directory, and the file name is redis.conf (Windows name is redis.windows.conf).

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

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
 "loglevel"
 "notice"

Use * to get all configuration items:

Instance:

redis 127.0.0.1:6379> CONFIG GET *
  "dbfilename"
  "dump.rdb"
  "requirepass"
  ""
  "masterauth"
  ""
  "unixsocket"
 ""
 "logfile"
 ""
 "pidfile"
 "/var/run/redis.pid"
 "maxmemory"
 "0"
 "maxmemory-samples"
 "3"
 "timeout"
 "0"
 "tcp-keepalive"
 "0"
 "auto-aof-rewrite-percentage"
 "100"
 "auto-aof-rewrite-min-size"
 "67108864"
 "hash-max-ziplist-entries"
 "512"
 "hash-max-ziplist-value"
 "64"
 "list-max-ziplist-entries"
 "512"
 "list-max-ziplist-value"
 "64"
 "set-max-intset-entries"
 "512"
 "zset-max-ziplist-entries"
 "128"
 "zset-max-ziplist-value"
 "64"
 "hll-sparse-max-bytes"
 "3000"
 "lua-time-limit"
 "5000"
 "slowlog-log-slower-than"
 "10000"
 "latency-monitor-threshold"
 "0"
 "slowlog-max-len"
 "128"
 "port"
 "6379"
 "tcp-backlog"
 "511"
 "databases"
 "16"
 "repl-ping-slave-period"
 "10"
 "repl-timeout"
 "60"
 "repl-backlog-size"
 "1048576"
 "repl-backlog-ttl"
 "3600"
 "maxclients"
 "4064"
 "watchdog-period"
 "0"
 "slave-priority"
 "100"
 "min-slaves-to-write"
 "0"
 "min-slaves-max-lag"
 "10"
 "hz"
 "10"
 "no-appendfsync-on-rewrite"
 "no"
 "slave-serve-stale-data"
 "yes"
 "slave-read-only"
 "yes"
 "stop-writes-on-bgsave-error"
 "yes"
 "daemonize"
 "no"
 "rdbcompression"
 "yes"
 "rdbchecksum"
 "yes"
 "activerehashing"
 "yes"
 "repl-disable-tcp-nodelay"
 "no"
 "aof-rewrite-incremental-fsync"
 "yes"
 "appendonly"
 "no"
 "dir"
 "/home/deepak/Downloads/redis-2.8.13/src"
 "maxmemory-policy"
 "volatile-lru"
 "appendfsync"
 "everysec"
 "save"
 "3600 1 300 100 60 10000"
 "loglevel"
 "notice"
 "client-output-buffer-limit"
 "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
 "unixsocketperm"
 "0"
 "slaveof"
 ""
 "notify-keyspace-events"
 ""
 "bind"
 ""

Edit configuration

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

Syntax

CONFIG SET command basic syntax:

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

Example:

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

redis.conf Configuration item description is as follows:

1. daemonize no
Redis does not run as a daemon process by default. You can modify it through this configuration item and use yes to enable the daemon process (Windows does not support the configuration of daemon threads as no)

2. pidfile /var/run/redis.pid
When Redis runs in daemon mode, Redis will write the pid into the /var/run/redis.pid file by default, which can be specified through pidfile

3. port 6379
specifies the Redis listening port. The default port is 6379. The author explained in one of his blog posts why 6379 was chosen as the default port because 6379 is the number corresponding to MERZ on the phone button, and MERZ is taken from the Italian singer Alessia. Merz’s name

4, bind 127.0.0.1
Bound host address

5, timeout 300
How long the client will be idle before closing the connection, if specified as 0, indicating that the function is turned off

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

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

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

9. save 0e72eeb93e8222d25f37582edca0e1bc 4dea9aacc34f4f894db964a9b08d412e

Redis default configuration file provides three conditions:

save 900 1

save 300 10

save 60 10000

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

Specify how many update operations there are within a long period of time, and then synchronize the data to the data file. Multiple conditions can be matched

10, rdbcompression yes
Specify to store it in the local database Whether to compress the data, the default is yes, Redis uses LZF compression, if you want to save CPU time, you can turn off this option, but it will cause the database file to become huge

11, dbfilename dump.rdb
Specify local Database file name, the default value is dump.rdb

12. dir ./
Specify the local database storage directory

13. slaveof 885bfb4ff5ca07b2526cbc210fcbc359 bee3afa7d8a7e90f2cbebf88c3647012
Settings When this machine serves slav, set the IP address and port of the master service. When Redis starts, it will automatically synchronize data from the master

14. masterauth e89d8186dfe17d1f70030d3fa2b7ff66
When the master When the service is password protected, the password for the slav service to connect to the master

15, requirepass foobared
Set the Redis connection password. If a connection password is configured, the client needs to pass AUTH cb1ebc435675187bdcfb539b370c2e37 when connecting to Redis. The command provides a password and is closed by default.

16, maxclients 128
Set the maximum number of client connections at the same time. The default is unlimited. The number of client connections that Redis can open at the same time is the maximum file description that the Redis process can open. Number of characters. If maxclients is set to 0, it means no limit. When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients reached error message to the client

17, maxmemory 4d5e782727adce28d9e975bcb1fbc12c
Specifies the maximum memory limit of Redis, Redis Data will be loaded into memory at startup. After reaching the maximum memory, Redis will first try to clear expired or expiring keys. After this method is processed, the maximum memory setting is still reached, and writing operations will no longer be possible. , but read operations are still possible. Redis's new vm mechanism will store Key in memory and Value in swap area

18, appendonly no
Specifies whether to log after each update operation. Redis is asynchronous by default Write data to disk. If not turned on, data may be lost for a period of time during 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. The default is no

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

20, appendfsync everysec

Specifies the update Log conditions, there are 3 optional values:

no: means waiting for the operating system to synchronize the data cache to the disk (fast) always: means manually calling fsync() after each update operation to write the data to the disk (slow, safe) everysec: means synchronizing once per second (folded) , the default value)

21, vm-enabled no
Specify whether to enable the virtual memory mechanism, the default value is no, briefly introduce, the VM mechanism stores data in pages, and Redis will access more The few pages that are cold data are swapped to the disk, and the pages that are accessed more are automatically swapped out from the disk to the memory (I will carefully analyze the VM mechanism of Redis in a later article)

22, vm-swap-file /tmp/redis.swap
Virtual memory file path, the default value is /tmp/redis.swap, which cannot be shared by multiple Redis instances

23, vm-max-memory 0
Replace all files larger than The data of 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 (the index data of Redis is keys). That is to say, when vm-max-memory is set When it is 0, all values ​​actually exist on the disk. The default value is 0

24, vm-page-size 32
The Redis swap file is divided into many pages. One object can be saved on multiple pages, but one page cannot be shared by multiple objects. , vm-page-size should be set according to the size of the stored data. The author recommends that if you store many small objects, the page size is best set to 32 or 64 bytes; if you store very large objects, you can use a larger page. If you are not sure, use the default value

25, vm-pages 134217728
Set the number of pages in the swap file, because the page table (a bitmap indicating that the page is free or used) is placed in the memory , every 8 pages on disk will consume 1byte of memory.

26. vm-max-threads 4
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 will be serial. Yes, it may cause a long delay. The default value is 4

27, glueoutputbuf yes
Sets whether to combine smaller packets into one packet and send them when responding to the client. The default is on

28, hash- max-zipmap-entries 64hash-max-zipmap-value 512
Specifies that a special hash algorithm is used when a certain number is exceeded or the largest element exceeds a certain critical value

29, activerehashing yes
Specifies whether to activate reset hashing, the default is on (details will be introduced later when introducing the Redis hash algorithm)

30, include /path/to/local.conf
Specify include For other configuration files, you can use the same configuration file between multiple Redis instances on the same host, and each instance has its own specific configuration file

For more Redis related knowledge, please visit Redis usage tutorial column!

The above is the detailed content of How to configure redis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn