【拼团 2-05 人群标签】
本章以轻量化的方式构建人群标签数据,将人群数据写入到 Redis BitMap 用于后续使用。
需要连接Redis,我连接的是阿里云云服务器的redis docker容器,遇到以下报错:
'''
Caused by: java.util.concurrent.CompletionException: org.redisson.client.RedisException: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error..
'''
简述:应用连接 Redis 成功,但 Redis 因 RDB 持久化失败而禁止写入操作,导致连接初始化失败,redis 日志显示如下:
"Failed opening the RDB file dog (in server root dir /etc/cron.d) for saving: Permission denied"
后果:Redis 进入写保护模式(read-only),拒绝所有写入请求。
错误原因:
错误的路径:Redis 试图将 RDB 快照保存到 /etc/cron.d/dog (/etc/cron.d 是 Linux 系统的定时任务目录,不允许非 root 用户写入。Redis 默认以 redis 用户运行,无此目录的写权限。)
Redis 的 dir 配置被显式或隐式设置为 /etc/cron.d(可能是人为误配或容器启动参数错误)。
并非 Docker 默认路径:官方 Redis 镜像的默认持久化目录是 /data。
解决:
1. 进入容器创建专用目录
docker exec -it redis mkdir -p /data/redis
docker exec -it redis chown redis:redis /data/redis
2. 修改 Redis 配置
(1)临时生效
docker exec -it redis redis-cli CONFIG SET dir /data/redis
docker exec -it redis redis-cli CONFIG SET dbfilename dump.rdb
(2)永久生效
# redis.conf
dir /data/redis
dbfilename dump.rdb
3. 重启容器
docker restart redis