使用Redis无需停机即可丢失数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Redis无需停机即可丢失数据相关的知识,希望对你有一定的参考价值。
Redis似乎丢失了我的一些数据,没有服务器进程死亡。第一个持续存在的新数据似乎是在12:26。 Redis的日志如下。 redis-cli info stats显示进程正常运行时间为3天。这个RDB后台保存失败了吗?有足够的磁盘空间可用。
Redis版本是4.0.6
24121:M 16 Dec 12:17:26.011 * 10 changes in 300 seconds. Saving...
24121:M 16 Dec 12:17:26.117 * Background saving started by pid 370
370:C 16 Dec 12:17:44.994 * DB saved on disk
370:C 16 Dec 12:17:45.068 * RDB: 167 MB of memory used by copy-on-write
24121:M 16 Dec 12:17:45.260 * Background saving terminated with success
24121:M 16 Dec 12:21:19.891 * DB saved on disk
24121:M 16 Dec 12:21:21.465 * DB saved on disk
24121:M 16 Dec 12:22:00.152 * DB saved on disk
24121:M 16 Dec 12:22:00.474 * DB saved on disk
24121:M 16 Dec 12:22:32.699 * DB saved on disk
24121:M 16 Dec 12:22:33.044 * DB saved on disk
24121:M 16 Dec 12:22:33.579 * DB saved on disk
24121:M 16 Dec 12:22:33.993 * DB saved on disk
24121:M 16 Dec 12:22:34.462 * DB saved on disk
24121:M 16 Dec 12:22:35.167 * DB saved on disk
24121:M 16 Dec 12:22:35.500 * DB saved on disk
24121:M 16 Dec 12:22:36.107 * DB saved on disk
24121:M 16 Dec 12:23:02.170 * DB saved on disk
24121:M 16 Dec 12:23:02.564 * DB saved on disk
24121:M 16 Dec 12:23:02.853 * DB saved on disk
24121:M 16 Dec 12:23:03.142 * DB saved on disk
24121:M 16 Dec 12:23:03.505 * DB saved on disk
24121:M 16 Dec 12:23:03.792 * DB saved on disk
24121:M 16 Dec 12:23:04.174 * DB saved on disk
24121:M 16 Dec 12:23:04.526 * DB saved on disk
24121:M 16 Dec 12:23:04.898 * DB saved on disk
24121:M 16 Dec 12:23:05.214 * DB saved on disk
24121:M 16 Dec 12:23:05.573 * DB saved on disk
24121:M 16 Dec 12:23:06.078 * DB saved on disk
24121:M 16 Dec 12:23:06.266 * DB saved on disk
24121:M 16 Dec 12:23:06.452 * DB saved on disk
24121:M 16 Dec 12:23:19.422 * DB saved on disk
24121:M 16 Dec 12:23:29.048 * DB saved on disk
24121:M 16 Dec 12:23:38.699 * DB saved on disk
24121:M 16 Dec 12:23:48.633 * DB saved on disk
24121:M 16 Dec 12:23:58.422 * DB saved on disk
24121:M 16 Dec 12:24:08.165 * DB saved on disk
24121:M 16 Dec 12:24:18.620 * DB saved on disk
24121:M 16 Dec 12:24:28.847 * DB saved on disk
24121:M 16 Dec 12:24:38.802 * DB saved on disk
24121:M 16 Dec 12:24:48.660 * DB saved on disk
24121:M 16 Dec 12:24:58.978 * DB saved on disk
24121:M 16 Dec 12:25:11.011 * DB saved on disk
24121:M 16 Dec 12:25:21.948 * DB saved on disk
24121:M 16 Dec 12:25:32.383 * DB saved on disk
24121:M 16 Dec 12:25:43.789 * DB saved on disk
24121:M 16 Dec 12:25:58.678 * DB saved on disk
24121:M 16 Dec 12:26:10.804 * DB saved on disk
24121:M 16 Dec 12:26:21.522 * DB saved on disk
24121:M 16 Dec 12:26:32.147 * DB saved on disk
24121:M 16 Dec 12:26:42.517 * DB saved on disk
24121:M 16 Dec 12:26:52.922 * DB saved on disk
24121:M 16 Dec 12:31:53.081 * 10 changes in 300 seconds. Saving...
24121:M 16 Dec 12:31:53.092 * Background saving started by pid 8671
8671:C 16 Dec 12:31:54.833 * DB saved on disk
8671:C 16 Dec 12:31:54.839 * RDB: 12 MB of memory used by copy-on-write
24121:M 16 Dec 12:31:54.898 * Background saving terminated with success
答案
我想这个FAQ提供了你的问题的答案:
Redis并没有随机丢失密钥。如果密钥已消失,则可能是由于以下原因之一:
到期:密钥上指定的TTL被命中,因此系统删除了密钥。有关Redis到期的更多详细信息,请参阅Expires命令的文档。可以通过SET,PSETEX或EXPIRE等操作设置TTL值。
INFO命令可用于使用STATS部分下的expired_keys条目获取有关密钥已过期的统计信息。您还可以在KEYSPACE部分中查看具有TTL值的键数以及平均TTL值。
# Stats expired_keys:46583 # Keyspace db0:keys=3450,expires=2,avg_ttl=91861015336 See related article with debugging tips
驱逐:在内存压力下,系统将驱逐钥匙以释放内存。当INFO命令中的used_memory或used_memory_rss值接近配置的
maxmemory
设置时,系统将根据您配置的内存策略开始从内存中逐出密钥,如此处所述。您可以使用前面提到的相同INFO命令监控被驱逐的密钥数量# Stats evicted_keys:13224
以上是关于使用Redis无需停机即可丢失数据的主要内容,如果未能解决你的问题,请参考以下文章