


Redis configuration file redis.conf detailed configuration instructions
This article lists the detailed description of each configuration item of the Redis configuration file redis.conf. It is simple and easy to understand. Friends in need can refer to it.
redis.conf configuration item description is as follows
redis configuration file detailed explanation
# vi redis.conf daemonize yes #是否以后台进程运行 pidfile /var/run/redis/redis-server.pid #pid文件位置 port 6379#监听端口 bind 127.0.0.1 #绑定地址,如外网需要连接,设置0.0.0.0 timeout 300 #连接超时时间,单位秒 loglevel notice #日志级别,分别有: # debug :适用于开发和测试 # verbose :更详细信息 # notice :适用于生产环境 # warning :只记录警告或错误信息 logfile /var/log/redis/redis-server.log #日志文件位置 syslog-enabled no #是否将日志输出到系统日志 databases 16#设置数据库数量,默认数据库为0 ############### 快照方式 ############### save 900 1 #在900s(15m)之后,至少有1个key发生变化,则快照 save 300 10 #在300s(5m)之后,至少有10个key发生变化,则快照 save 60 10000 #在60s(1m)之后,至少有1000个key发生变化,则快照 rdbcompression yes #dump时是否压缩数据 dir /var/lib/redis #数据库(dump.rdb)文件存放目录 ############### 主从复制 ############### slaveof <masterip> <masterport> #主从复制使用,用于本机redis作为slave去连接主redis masterauth <master-password> #当master设置密码认证,slave用此选项指定master认证密码 slave-serve-stale-data yes #当slave与master之间的连接断开或slave正在与master进行数据同步时,如果有slave请求,当设置为yes时,slave仍然响应请求,此时可能有问题,如果设置no时,slave会返回"SYNC with master in progress"错误信息。但INFO和SLAVEOF命令除外。 ############### 安全 ############### requirepass foobared #配置redis连接认证密码 ############### 限制 ############### maxclients 128#设置最大连接数,0为不限制 maxmemory <bytes>#内存清理策略,如果达到此值,将采取以下动作: # volatile-lru :默认策略,只对设置过期时间的key进行LRU算法删除 # allkeys-lru :删除不经常使用的key # volatile-random :随机删除即将过期的key # allkeys-random :随机删除一个key # volatile-ttl :删除即将过期的key # noeviction :不过期,写操作返回报错 maxmemory-policy volatile-lru#如果达到maxmemory值,采用此策略 maxmemory-samples 3 #默认随机选择3个key,从中淘汰最不经常用的 ############### 附加模式 ############### appendonly no #AOF持久化,是否记录更新操作日志,默认redis是异步(快照)把数据写入本地磁盘 appendfilename appendonly.aof #指定更新日志文件名 # AOF持久化三种同步策略: # appendfsync always #每次有数据发生变化时都会写入appendonly.aof # appendfsync everysec #默认方式,每秒同步一次到appendonly.aof # appendfsync no #不同步,数据不会持久化 no-appendfsync-on-rewrite no #当AOF日志文件即将增长到指定百分比时,redis通过调用BGREWRITEAOF是否自动重写AOF日志文件。 ############### 虚拟内存 ############### vm-enabled no #是否启用虚拟内存机制,虚拟内存机将数据分页存放,把很少访问的页放到swap上,内存占用多,最好关闭虚拟内存 vm-swap-file /var/lib/redis/redis.swap #虚拟内存文件位置 vm-max-memory 0 #redis使用的最大内存上限,保护redis不会因过多使用物理内存影响性能 vm-page-size 32 #每个页面的大小为32字节 vm-pages 134217728 #设置swap文件中页面数量 vm-max-threads 4 #访问swap文件的线程数 ############### 高级配置 ############### hash-max-zipmap-entries 512 #哈希表中元素(条目)总个数不超过设定数量时,采用线性紧凑格式存储来节省空间 hash-max-zipmap-value 64 #哈希表中每个value的长度不超过多少字节时,采用线性紧凑格式存储来节省空间 list-max-ziplist-entries 512 #list数据类型多少节点以下会采用去指针的紧凑存储格式 list-max-ziplist-value 64 #list数据类型节点值大小小于多少字节会采用紧凑存储格式 set-max-intset-entries 512 #set数据类型内部数据如果全部是数值型,且包含多少节点以下会采用紧凑格式存储 activerehashing yes #是否激活重置哈希
Summary:
1. Redis provides several persistence mechanisms:
a). RDB persistence
Working method: according to time interval Snapshot (dump) the data in redis to the dump.rdb file
Advantages: Simple backup and recovery. RDB completes persistence work through child processes, which is relatively more efficient than AOF startup
Disadvantage: server failure will lose data within a few minutes
b). AOF persistence
Working method: Record all update operations in the form of logs to the AOF log file. When the redis service is restarted, the log file will be read to rebuild the database to ensure data integrity after startup.
Advantages: AOF provides two synchronization mechanisms, one is fsync always synchronizes to the log file every time there is a data change, and fsync everysec synchronizes to the log file once per second to maximize data integrity.
Disadvantage: The log file is much larger than the RDB snapshot file
AOF log rewriting function:
If the AOF log file is too large, redis will Automatically rewrite the AOF log. The append mode continuously writes updated records to the old log file. At the same time, redis will also create a new log file for appending subsequent records.
c). Apply AOF and RDB at the same time
For scenarios with high data security, AOF and RDB can be used at the same time, which will reduce performance.
d). No persistence
Disable the redis service persistence function.
2. After the AOF log file has an error, the repair method :
redis-check-aof --fix appendonly.aof #--fix parameter is to repair the log file. If not added, check the log
3. Switch from RDB persistence to AOF persistence without restarting redis:
redis-cli> CONFIG SET appendonly yes #启用AOF redis-cli> CONFIG SET save "" #关闭RDB
The redis configuration file details the basic configuration of redis. The items are relatively common. When using redis, you must understand these configuration items
Related recommendations:
Redis configuration file redis.conf Detailed explanation
[Redis Notes] Part 4: Description of the Replication configuration item in redis.conf
The above is the detailed content of Redis configuration file redis.conf detailed configuration instructions. 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



Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

Using Redis to lock operations requires obtaining the lock through the SETNX command, and then using the EXPIRE command to set the expiration time. The specific steps are: (1) Use the SETNX command to try to set a key-value pair; (2) Use the EXPIRE command to set the expiration time for the lock; (3) Use the DEL command to delete the lock when the lock is no longer needed.

The best way to understand Redis source code is to go step by step: get familiar with the basics of Redis. Select a specific module or function as the starting point. Start with the entry point of the module or function and view the code line by line. View the code through the function call chain. Be familiar with the underlying data structures used by Redis. Identify the algorithm used by Redis.

Redis data loss causes include memory failures, power outages, human errors, and hardware failures. The solutions are: 1. Store data to disk with RDB or AOF persistence; 2. Copy to multiple servers for high availability; 3. HA with Redis Sentinel or Redis Cluster; 4. Create snapshots to back up data; 5. Implement best practices such as persistence, replication, snapshots, monitoring, and security measures.

There are two types of Redis data expiration strategies: periodic deletion: periodic scan to delete the expired key, which can be set through expired-time-cap-remove-count and expired-time-cap-remove-delay parameters. Lazy Deletion: Check for deletion expired keys only when keys are read or written. They can be set through lazyfree-lazy-eviction, lazyfree-lazy-expire, lazyfree-lazy-user-del parameters.
