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:
1 |
|
Instance:
1 2 3 |
|
Use * to get all configuration items:
Instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
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:
1 |
|
Example:
1 2 3 4 5 |
|
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
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
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
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
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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redisactsasbothadatastoreandaservice.1)Asadatastore,itusesin-memorystorageforfastoperations,supportingvariousdatastructureslikekey-valuepairsandsortedsets.2)Asaservice,itprovidesfunctionalitieslikepub/submessagingandLuascriptingforcomplexoperationsan

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

Redis is a NoSQL database that provides high performance and flexibility. 1) Store data through key-value pairs, suitable for processing large-scale data and high concurrency. 2) Memory storage and single-threaded models ensure fast read and write and atomicity. 3) Use RDB and AOF mechanisms to persist data, supporting high availability and scale-out.
