From 40732c011b600183533cb8352c5a8f91e9de8d74 Mon Sep 17 00:00:00 2001 From: wangbo Date: Tue, 25 Aug 2026 16:24:36 +0800 Subject: [PATCH] =?UTF-8?q?perf(redis):=20=E5=A2=9E=E5=BC=BA=E6=8C=81?= =?UTF-8?q?=E4=B9=85=E5=8C=96=E4=B8=8E=E4=BC=98=E9=9B=85=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 1 + redis.conf | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f045e24..293ea83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -231,6 +231,7 @@ services: - ./redis.conf:/etc/redis/redis.conf # 挂载本地 redis.conf - ./data/redis:/data # 持久化 Redis AOF/RDB,避免落到容器写层 command: [ "redis-server", "/etc/redis/redis.conf" ] # 让 Redis 读取配置文件 + stop_grace_period: 1m # 给 Redis 足够时间在 SIGTERM 后完成 AOF fsync mem_limit: 2g memswap_limit: 2g # ports: diff --git a/redis.conf b/redis.conf index c863994..746ef3b 100755 --- a/redis.conf +++ b/redis.conf @@ -31,17 +31,25 @@ tcp-backlog 511 replica-read-only no # 设置Redis最大内存达到时的数据淘汰策略 -# noeviction:当内存达到最大限制时,Redis不会自动删除任何键,这可能导致进一步的操作失败,直到手动干预 # 当内存不足时,删除最近最少使用的键 +# 为 2GB 容器预留约 512MB,供连接缓冲区、模块、AOF 重写和 fork/COW 使用。 +# noeviction:达到数据内存上限后拒绝写入,避免淘汰队列内部键导致状态不一致。 # maxmemory-policy allkeys-lru -maxmemory 2gb +maxmemory 1536mb maxmemory-policy noeviction # 设置数据库数量,这里设置为16个数据库 databases 16 # AOF 常规配置 appendfsync everysec -no-appendfsync-on-rewrite yes +# AOF/RDB 重写期间继续 fsync,优先保证异常退出后的数据完整性。 +no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb +# 自动修复意外 EOF;Redis 8.4+ 可额外截断小范围格式损坏尾部。 +aof-load-truncated yes +aof-load-corrupt-tail-max-size 4096 +# 使用 RDB 作为 AOF 基础文件并增量刷盘,降低重写和恢复开销。 +aof-use-rdb-preamble yes +aof-rewrite-incremental-fsync yes # 慢查询阈值 slowlog-log-slower-than 10000 slowlog-max-len 128 @@ -67,5 +75,3 @@ list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 - -