在写入Redis (SET foo bar)期间,我得到以下错误:

MISCONF Redis被配置为保存RDB快照,但当前为 无法在磁盘上持久保存。可能修改数据集的命令是 禁用。有关错误的详细信息,请查看Redis日志。

基本上我理解的问题是,redis是不能在磁盘上保存数据,但不知道如何摆脱这个问题。

下面的问题也有同样的问题,它在很久以前就被抛弃了,没有答案,很可能没有尝试解决这个问题。


当前回答

如果您正在运行MacOS,并且最近升级到Catalina,您可能需要按照本问题的建议运行brew服务重新启动redis。

其他回答

我知道这个线程稍微老一些,但当我早些时候得到这个错误时,这里是为我工作的,因为我知道我没有接近内存限制-两个答案都在上面找到。

希望这能在将来帮助到需要的人。

检查CHMOD目录…发现符号符号不一样。CHMOD目录文件夹到755 Dbfilename权限很好,不需要更改 重启redis-server 参考redis-server.log,发现该错误是访问被拒绝的结果。

再次-不确定DIR文件夹的权限是如何改变的,但我假设CHMOD回到755并重新启动redis-server,因为我之后能够ping到redis服务器。

另外,需要注意的是,redis确实拥有dbfilename和DIR文件夹的所有权。

在我绞尽脑汁思考了这么多so问题之后,终于 对我来说,@Axel Advento的回答奏效了,但没有额外的步骤- 我仍然面临许可问题。 我必须切换用户到redis,在它的home目录中创建一个新目录,然后将其设置为redis的目录。

sudo su - redis -s /bin/bash
mkdir redis_dir
redis-cli CONFIG SET dir $(realpath redis_dir)
exit # to logout from redis user (optional)

在我的情况下,这只是特权,我需要允许Redis接受传入的请求。

所以我重启了Redis服务通过Homebrew brew服务停止Redis和brew服务启动Redis和运行Redis服务器本地Redis -server。命令提示符要求我允许传入请求,然后它开始工作。

在我的例子中,原因是磁盘的可用空间非常低(只有35 Mb)。我做了以下的事情

停止所有Redis相关进程 删除磁盘中的一些文件,以腾出足够的空间 删除redis转储文件(如果不需要现有数据) Sudo rm /var/lib/redis/* 删除所有现有数据库的所有键 Sudo redis-cli flushall 重新启动所有芹菜任务,并检查相应的日志是否有任何问题

此错误是由于BGSAVE失败导致的。在BGSAVE期间,Redis会fork一个子进程来将数据保存到磁盘上。虽然BGSAVE失败的确切原因可以从日志中检查(通常在linux机器上的/var/log/redis/redis-server.log),但很多时候bgive失败是因为fork不能分配内存。很多时候,由于操作系统的优化冲突,fork无法分配内存(尽管机器有足够的可用RAM)。

可以从Redis常见问题中阅读:

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can't tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail. Setting overcommit_memory to 1 says Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.

Redis不需要像操作系统认为的那样多的内存来写入磁盘,所以可能会预先导致fork失败。

要解决这个问题,您可以:

修改/etc/sysctl.conf,增加:

vm.overcommit_memory=1

然后重新启动sysctl:

在FreeBSD上:

sudo /etc/rc.d/sysctl reload

在Linux上:

sudo sysctl -p /etc/sysctl.conf