search
HomeDatabaseRedisHow to configure redis

How to configure redis

Jul 05, 2019 pm 02:57 PM

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

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 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
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
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

Redis: A Guide to Key-Value Data StoresRedis: A Guide to Key-Value Data StoresMay 02, 2025 am 12:10 AM

Redis is an open source memory data structure storage used as a database, cache and message broker, suitable for scenarios where fast response and high concurrency are required. 1.Redis uses memory to store data and provides microsecond read and write speed. 2. It supports a variety of data structures, such as strings, lists, collections, etc. 3. Redis realizes data persistence through RDB and AOF mechanisms. 4. Use single-threaded model and multiplexing technology to handle requests efficiently. 5. Performance optimization strategies include LRU algorithm and cluster mode.

Redis: Caching, Session Management, and MoreRedis: Caching, Session Management, and MoreMay 01, 2025 am 12:03 AM

Redis's functions mainly include cache, session management and other functions: 1) The cache function stores data through memory to improve reading speed, and is suitable for high-frequency access scenarios such as e-commerce websites; 2) The session management function shares session data in a distributed system and automatically cleans it through an expiration time mechanism; 3) Other functions such as publish-subscribe mode, distributed locks and counters, suitable for real-time message push and multi-threaded systems and other scenarios.

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

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.