Redis configuration file Detailed _redis

Source: Internet
Author: User
Tags message queue redis value store

If you think that Redis is a key value store, you can use it instead of MySQL, and if you think it is a persistent cache, you might just use it to save some of the frequently accessed temporary data (instead of memcached); Redis can also be used as a lightweight message queue because it has built-in support for the list data structure and PUB/SUB commands, as well as a lightweight distributed lock system. Redis is the abbreviation for Remote DIctionary server, explained in Redis on the official website:

Copy Code code as follows:

Redis is an open source, Advanced Key-value store.
It is often referred to as a data structure server since keys
Can contain strings, hashes, lists, sets and sorted sets.

This article will detail the configuration file for Redis.

1. Redis is not run as a daemon by default, and can be modified using Yes to enable the daemon process

Copy Code code as follows:

Daemonize No

2. When Redis is running as a daemon, Redis writes the PID to the/var/run/redis.pid file by default, which can be specified by pidfile
Copy Code code as follows:

Pidfile/var/run/redis.pid

3. Specify the Redis listening port, the default port is 6379, the author in his own posting explained why 6379 as the default port, because 6379 on the phone button on the number of Merz, and Merz from the Italian singer Alessia Merz name
Copy Code code as follows:

Port 6379

4. The host address of the binding
Copy Code code as follows:

Bind 127.0.0.1

5. Close the connection when the client is idle for a long time, or 0 if specified, to turn off the feature
Copy Code code as follows:

Timeout 300

6. Specify logging level, Redis supports four levels in total: Debug, verbose, notice, warning, default to verbose
Copy Code code as follows:

LogLevel verbose

7. Logging mode, default to standard output, if the configuration redis for the daemon mode, and this is configured as logging mode for standard output, the log will be sent to/dev/null
Copy Code code as follows:

LogFile stdout

8. Set the number of databases, the default database is 0, you can use the Select <dbid> command to specify the database ID on the connection
Copy Code code as follows:

Databases 16

9. Specify how long, how many times the update operation, the data synchronized to the data file, can be multiple conditions with
Copy Code code as follows:

Save <seconds> <changes>

There are three conditions available in the Redis default configuration file:
Copy Code code as follows:

Save 900 1
Save 300 10
Save 60 10000

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

10. Specifies whether to compress the data when stored to the local database, the default is Yes,redis with 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

Copy Code code as follows:

Rdbcompression Yes

11. Specify the local database filename, the default value is Dump.rdb
Copy Code code as follows:

Dbfilename Dump.rdb

12. Specify local Database storage directory
Copy Code code as follows:

Dir./

13. Set the IP address and port of master service when this machine is Slav service, it automatically synchronizes data from master when Redis is started
Copy Code code as follows:

Slaveof <masterip> <masterport>

14. When the master service is password protected, the Slav service connects Master's password
Copy Code code as follows:

Masterauth <master-password>

15. Set the Redis connection password, if the connection password is configured, the client will need to provide the password through auth <password> command when connecting Redis, the default shutdown
Copy Code code as follows:

Requirepass foobared

16. Set the maximum number of client connections at the same time, the default unrestricted, Redis can open the number of client connections Redis process can open the maximum number of file descriptors, if set maxclients 0, which means no restrictions. When the number of client connections reaches a limit, Redis closes the new connection and returns the max number of clients reached error message to the client
Copy Code code as follows:

MaxClients 128

17. Specify Redis maximum memory limit, Redis will load the data into memory at startup, and after reaching maximum memory, Redis will attempt to clear a key that has expired or is about to expire, and when this method is processed, it still reaches the maximum memory setting, no more writes will be made, but the read operation is still available. Redis the new VM mechanism, the key is stored in memory, and value is stored in the swap area
Copy Code code as follows:

MaxMemory <bytes>

18. Specifies whether to log records after each update operation, redis the data to disk by default and, if not, may result in loss of data for a period of time if the power is not turned on. Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. Default is No
Copy Code code as follows:

AppendOnly No

19. Specify update log file name, default to Appendonly.aof
Copy Code code as follows:

Appendfilename appendonly.aof

20. Specify an update log condition with 3 optional values:
No: Indicates that the operating system synchronizes data cache to disk (fast)
Always: Indicates that Fsync () is manually invoked after each update operation () to write data to disk (slow, secure)
Everysec: Indicates sync per second (compromise, default)
Copy Code code as follows:

Appendfsync everysec

21. Specifies whether the virtual memory mechanism is enabled, the default is no, a simple introduction, the VM mechanism to store data paging, by Redis will be less visited the page that cold data swap to disk, Access to many pages from the disk automatically swapped out into memory (in the following article I will carefully analyze the VM mechanism of Redis)
Copy Code code as follows:

Vm-enabled No

22. Virtual memory file path, default value is/tmp/redis.swap, not multiple Redis instance sharing
Copy Code code as follows:

Vm-swap-file/tmp/redis.swap

23. Save all data larger than vm-max-memory into virtual memory, no matter how small the Vm-max-memory settings, all index data is memory storage (Redis index data is the keys), that is to say, when the vm-max-memory is set to 0, In fact, all of the value exists on the disk. The default value is 0
Copy Code code as follows:

Vm-max-memory 0

Redis swap file is divided into a lot of page, an object can be saved on multiple page, but a page can not be shared by multiple objects, Vm-page-size is based on the size of the stored data set, the authors suggest that if you store a lot of small objects, The page size is best set to 32 or 64bytes; If you store a large object, you can use a larger page and, if unsure, use the default value
Copy Code code as follows:

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 in memory, which consumes 1byte of memory per 8 pages on disk.
Copy Code code as follows:

Vm-pages 134217728

26. Set the number of threads to access the swap file, preferably do not exceed the machine's core, if set to 0, then all operation of the swap file is serial, may cause a relatively long delay. The default value is 4
Copy Code code as follows:

Vm-max-threads 4

27. Set when replying to the client, whether to merge the smaller packages into one package send, default to open
Copy Code code as follows:

Glueoutputbuf Yes

28. Specifies that a special hashing algorithm is used when more than a certain number or maximum element exceeds a critical value
Copy Code code as follows:

Hash-max-zipmap-entries 64
Hash-max-zipmap-value 512

29. Specifies whether to activate the reset hash, which is turned on by default (described later when introducing the hash algorithm for Redis)
Copy Code code as follows:

activerehashing Yes

30. Specifies that there are other configuration files that can use the same configuration file between multiple Redis instances on the same host, while each instance has its own specific configuration file
Copy Code code as follows:

Include/path/to/local.conf

This article has introduced the Redis configuration file completely, hoped is useful for everybody.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.