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: Improving Application Performance and ScalabilityRedis: Improving Application Performance and ScalabilityApr 17, 2025 am 12:16 AM

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis: Exploring Its Data Model and StructureRedis: Exploring Its Data Model and StructureApr 16, 2025 am 12:09 AM

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis: Classifying Its Database ApproachRedis: Classifying Its Database ApproachApr 15, 2025 am 12:06 AM

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.

Why Use Redis? Benefits and AdvantagesWhy Use Redis? Benefits and AdvantagesApr 14, 2025 am 12:07 AM

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,

Understanding NoSQL: Key Features of RedisUnderstanding NoSQL: Key Features of RedisApr 13, 2025 am 12:17 AM

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

Redis: Identifying Its Primary FunctionRedis: Identifying Its Primary FunctionApr 12, 2025 am 12:01 AM

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

Redis: A Guide to Popular Data StructuresRedis: A Guide to Popular Data StructuresApr 11, 2025 am 12:04 AM

Redis supports a variety of data structures, including: 1. String, suitable for storing single-value data; 2. List, suitable for queues and stacks; 3. Set, used for storing non-duplicate data; 4. Ordered Set, suitable for ranking lists and priority queues; 5. Hash table, suitable for storing object or structured data.

How to implement redis counterHow to implement redis counterApr 10, 2025 pm 10:21 PM

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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