search
HomeDatabaseRedisSuper detailed analysis of the Redis configuration file redis.conf

Super detailed analysis of the Redis configuration file redis.conf

Recommended (free): redis tutorial

Article Directory

  • 1. Thirty commonly used configurations
  • 2. Redis memory elimination strategy
    • 2.1 Set timeout for data
    • 2.2 Use LRU algorithm to dynamically delete unused data
  • 3. Custom configuration of Redis

Keep in mind when developing under Linux: The software is installed under /opt by default. Never directly change the configuration file with factory default settings. The correct way is toback up a copy before operating.

The Redis configuration file is located in the Redis installation directory. The file name is reids.conf. Here are thirty commonly used configurations. The article comes with the English translation of the redis.conf file. .

1. Thirty commonly used configurations


The first ten configurations

  • daemonize no
    Redis does not run as a daemon process by default. It can be modified to yes to enable the daemon process.

  • pidfile /var/run/redis/pid
    When Redis runs as a daemon, Redis will save the pid by default Write /var/run/redis.pid file, you can specify the path through pidfile.

  • port 6379
    Specify the listening port of Redis.

  • bind 127.0.0.1
    The host address bound by Redis.

  • timeout 300
    Set how long the client will be idle before closing the connection. If it is 0, it means turning off this function.

  • loglevel verbose
    Specify the logging level. Redis supports four levels: debug, verbose (default), notice, warning.

  • logfile stdout
    Logging mode, the default is standard output, if Redis is configured as a daemon process, and the logging here If the mode is standard output, the log will be sent to /dev/null

  • ##databases 16 Settings The number of databases. The default number is 0. You can use the
    select command to specify the database id on the connection.

  • ##save

    Specify how many update operations there are within a certain period of time, and then the Data is synchronized to data files and can be matched with multiple conditions. Three conditions are provided in the Redis configuration file: save 900 1; save 300 10; save 60 10000

  • rdbcompression

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


The middle ten configurations

    ##dbfilename
  • dump.rdb

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

  • dir
  • ./

    Specify the local database Storage directory

  • slaveof
  • Society When this machine serves slav, set the master service The IP address and port will automatically synchronize data from the master when Redis starts.

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

  • requirepass
  • foobared

    Set the connection password for Redis. If a connection password is configured, the client needs to pass# when connecting to Redis. ##AUTH<password></password>The command provides a password, which is turned off by default.

    maxclients
  • 128
  • Set the maximum number of client connections at the same time. The default is unlimited. Redis can open client connections at the same time. The number is the maximum number of file descriptors that the Redis process can open. If maxclients is set to 0, it means there is 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.
    ##maxmemory

  • Specifies the maximum memory limit of Redis. Redis will load data into memory when it starts. 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 write operations will not be possible, but read operations can still be performed. Redis' new vm mechanism stores the key in memory and the value in the swap area.
    appendonly

    no
  • Specifies whether to log after an update operation. Redis is one-stop by default. Writing data to disk, if not turned on, may result in data loss for a period of time during a power outage.

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

  • appendsync everysec
    Specify the update log conditions. There are three options:
    ①no: Indicates waiting for the operating system to complete The data cache is synchronized to the disk (fast),
    ②always: means manually calling fsync() to write the data to the disk after each update of the operating system (slow, safe),
    ③everysec: means wonderful synchronization once (efficiency compromise) , is the default value)

last ten

  • ##vm-enable no Specify whether to enable the virtual memory mechanism. The default value is no. The VM mechanism stores data in pages. Redis swaps the pages with less access, that is, cold data, to the disk. The pages with more access are automatically swapped out by the disk. in memory.
  • vm-swap-file /tmp/redis.swap Virtual memory file path, the default value is /tmp/redis.swap, not more than one Redis instance sharing.
  • vm-max-memory 0 Store all data larger than vm-max-memory in virtual memory, regardless of vm-max-memory settings Small, all index data is stored in memory (Redis index data is keys), that is to say, when vm-max-memory is set to 0, all values ​​actually exist on the disk. The default value is 0
  • vm-page-size 32 The Redis swap file is divided into many pages, and an object can be saved on multiple pages. However, a page cannot be shared by multiple objects. vm-page-size is set according to the size of the stored data. If many small objects are stored, the page size is best set to 32 or 64 bytes; if very large objects are stored, You can use a larger page. If you are not sure, use the default value.
  • 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 memory, every 8 pages on disk will consume 1 byte of memory.
  • vm-max-threads 4 Set the number of threads to access the swap file. Do not exceed the number of cores of the machine. If set to 0, then all pairs The operations of the swap file are all serial and may cause a long delay. The default value is 4.
  • glueoutputbuf yes Set whether to combine smaller packets into one packet and send it when responding to the client. The default is on.
  • hash-max-zipmap-entries 64/hash-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 threshold.
  • activerehashing yes Specifies whether to activate rehashing, the default is on.
  • include /path/to/local.conf Specifies the inclusion of other configuration files. You can use the same configuration file between multiple Redis instances on the same host. configuration files, and each instance has its own specific configuration file.

2. Redis’ memory elimination strategy

As an excellent cache middleware, Redis often stores a large amount of data, even if cluster deployment is used to dynamically When expanding capacity, memory should also be cleared immediately to maintain system performance.

2.1 Set the timeout for data

  • expire key time (in seconds) This is the most commonly used method
  • setex(String Key, int seconds, String value) String-unique method
In addition to the string's own unique method of setting the expiration time, other Methods all need to rely on the expire method to set the time.

If no time is set, the cache will never expire.
If you set an expiration time and later want the cache to never expire, use
persist key

2.2 Use the LRU algorithm to dynamically delete unused data

A page replacement algorithm for memory management. Data blocks (memory blocks) that are in the memory but are not used are called LRU. The operating system will remove them from the memory to make room for loading based on which data belongs to the LRU. additional data.

  1. volatile-lru    Among the data with set timeout period, delete the least commonly used data

  2. allkeys-lru    Query the least commonly used data among all keys and delete them. This is the most widely used strategy.

  3. volatile-random Randomly delete data that has been set with a timeout

  4. allkeys-random Query all keys, and then randomly delete

  5. volatile-ttl Query all data with a set timeout, and then sort them to collect the data of state-owned enterprises. Delete

  6. noeviction If set to this attribute, the deletion operation will not be performed, and an error will be returned if the memory overflows

  7. volatile-lfu    Remove the least frequently used key from all keys configured with a timeout

  8. allkeys-lfu Delete the least frequently used key from all keys

3. Custom configuration Redis

Enter the corresponding installation directory /usr/local/redis and modify the redis.conf configuration file.

As a beginner, Redis generally needs to modify the following three items:

  • Change daemonize no to daemonize yes, that is, it will be started as a daemon process instead.
  • Comment out bind 127.0.01 to allow machines other than the local machine to access the Redis service.
  • Use requirepass Set password, which ensures service security/in rare cases remote access is not possible without setting a password.

Redis adopts a single-process multi-thread mode. When the daemonize option in redis.conf is set to yes, it means that the daemon process mode is enabled. In this mode, redis will run in the background and write the process pid number to the file set by the redis.conf option pidfile. At this time, redis will always run unless the process is manually killed. But when the daemonize option is set to no, the current interface will enter the redis command line interface. Forced exit by exit or closing the connection tool (putty, xshell, etc.) will cause the redis process to exit. Most applications developed on the server side run in the background.

More related learning:redis

The above is the detailed content of Super detailed analysis of the Redis configuration file redis.conf. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Redis vs databases: performance comparisonsRedis vs databases: performance comparisonsMay 14, 2025 am 12:11 AM

Redisoutperformstraditionaldatabasesinspeedforread/writeoperationsduetoitsin-memorynature,whiletraditionaldatabasesexcelincomplexqueriesanddataintegrity.1)Redisisidealforreal-timeanalyticsandcaching,offeringphenomenalperformance.2)Traditionaldatabase

When Should I Use Redis Instead of a Traditional Database?When Should I Use Redis Instead of a Traditional Database?May 13, 2025 pm 04:01 PM

UseRedisinsteadofatraditionaldatabasewhenyourapplicationrequiresspeedandreal-timedataprocessing,suchasforcaching,sessionmanagement,orreal-timeanalytics.Redisexcelsin:1)Caching,reducingloadonprimarydatabases;2)Sessionmanagement,simplifyingdatahandling

Redis: Beyond SQL - The NoSQL PerspectiveRedis: Beyond SQL - The NoSQL PerspectiveMay 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: A Comparison to Traditional Database ServersRedis: A Comparison to Traditional Database ServersMay 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

Redis: Introduction to a Powerful In-Memory Data StoreRedis: Introduction to a Powerful In-Memory Data StoreMay 06, 2025 am 12:08 AM

Redisisahigh-performancein-memorydatastructurestorethatexcelsinspeedandversatility.1)Itsupportsvariousdatastructureslikestrings,lists,andsets.2)Redisisanin-memorydatabasewithpersistenceoptions,ensuringfastperformanceanddatasafety.3)Itoffersatomicoper

Is Redis Primarily a Database?Is Redis Primarily a Database?May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Database, Server, or Something Else?Redis: Database, Server, or Something Else?May 04, 2025 am 12:08 AM

Redisisamultifacetedtoolthatservesasadatabase,server,andmore.Itfunctionsasanin-memorydatastructurestore,supportsvariousdatastructures,andcanbeusedasacache,messagebroker,sessionstorage,andfordistributedlocking.

Redis: Unveiling Its Purpose and Key ApplicationsRedis: Unveiling Its Purpose and Key ApplicationsMay 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),