解决Redis报错Redis is configured to save RDB snapshots, but it is currently not able to persist on disk

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 解决Redis报错Redis is configured to save RDB snapshots, but it is currently not able to persist on disk

Redis报错信息

在Spring Boot中集成Redis客户之后,进行数据操作,发现报如下错误:

org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: 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.
  at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54)
  at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52)
  at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
  at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
  at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
  at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:270)
  at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799)
  at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:148)
  at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:281)
  at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:240)
  at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:60)
  at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228)
  at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
  at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
  at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)

报错原因

从Redis层面来分析错误的直接原因是:


Redis被配置为保存数据库快照,但它目前不能持久化到硬盘。用来修改集合数据的命令不能用。请查看Redis日志的详细错误信息。


也就是说,Redis无法将缓存中的数据写入本地磁盘。


针对Redis报错无法写入磁盘,往往有以下原因:


磁盘满了

Redis配置问题

操作权限问题

如果磁盘满了,直接清理磁盘或进行扩充即可。


解决方案

问题一

如果是权限问题,查看日志会发现如下日志:


11875:M 06 Mar 2020 09:00:12.034 * 1 changes in 3600 seconds. Saving...
11875:M 06 Mar 2020 09:00:12.035 * Background saving started by pid 12625
12625:C 06 Mar 2020 09:00:12.036 # Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis-5.0.7) for saving: Permission denied

如果是权限问题,则服务对应目录的权限,或在配置文件中修改目标目录到有权限操作的目录。

默认目录配置如下:

# The filename where to dump the DB
dbfilename dump.rdb
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

修改下面的dir路径:


dir /Users/zzs/tools/dbs

1

然后重启即可。在重启的过程中可能依然由于无法保存数据而死循环,此时就需要杀手锏了。


问题二

如果是配置问题导致,则可进行如下修改。


使用redis-cli连接上redis,然后执行如下命令:


config set stop-writes-on-bgsave-error no

1

通过将stop-writes-on-bgsave-error设置为no来进行解决。但这种方案治标不治本,从根本上来讲,还是需要大家查看后台异常原因,进行有针对性的解决。


相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
14天前
|
存储 缓存 NoSQL
大数据-45 Redis 持久化概念 RDB AOF机制 持久化原因和对比
大数据-45 Redis 持久化概念 RDB AOF机制 持久化原因和对比
31 2
大数据-45 Redis 持久化概念 RDB AOF机制 持久化原因和对比
|
29天前
|
存储 缓存 NoSQL
Redis中的rdb和aof
本文深入探讨了Redis的持久化机制,包括RDB和AOF两种方式。详细解释了RDB的工作原理、优势和劣势,以及AOF的实现原理、配置选项、文件重写机制和三种数据同步方式,还介绍了AOF文件修复工具redis-check-aof的使用,并通过实例展示了如何开启和配置AOF持久化方式。
Redis中的rdb和aof
|
14天前
|
存储 缓存 NoSQL
大数据-46 Redis 持久化 RDB AOF 配置参数 混合模式 具体原理 触发方式 优点与缺点
大数据-46 Redis 持久化 RDB AOF 配置参数 混合模式 具体原理 触发方式 优点与缺点
39 1
|
1月前
|
存储 NoSQL Redis
SpringCloud基础7——Redis分布式缓存,RDB,AOF持久化+主从+哨兵+分片集群
Redis持久化、RDB和AOF方案、Redis主从集群、哨兵、分片集群、散列插槽、自动手动故障转移
SpringCloud基础7——Redis分布式缓存,RDB,AOF持久化+主从+哨兵+分片集群
|
27天前
|
存储 NoSQL Redis
Redis的RDB快照:保障数据持久性的关键机制
Redis的RDB快照:保障数据持久性的关键机制
36 0
|
2月前
|
存储 缓存 NoSQL
【Azure Redis 缓存 Azure Cache For Redis】如何设置让Azure Redis中的RDB文件暂留更久(如7天)
【Azure Redis 缓存 Azure Cache For Redis】如何设置让Azure Redis中的RDB文件暂留更久(如7天)
|
2月前
|
NoSQL Java Redis
【Azure Webjob + Redis】WebJob一直链接Azure Redis一直报错 Timeout Exception
【Azure Webjob + Redis】WebJob一直链接Azure Redis一直报错 Timeout Exception
|
2月前
|
NoSQL Redis
【Azure Redis】Redis导入备份文件(RDB)失败的原因
【Azure Redis】Redis导入备份文件(RDB)失败的原因
|
2月前
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
|
2月前
|
缓存 NoSQL Redis
redis数据持久化之RDB和AOF
redis数据持久化之RDB和AOF