如何处理Redis引发内存碎片?

我有一个Redis 3.0.5实例,随着时间的推移,这个实例往往会显示增长的mem_fragmentation_ratio。

使用该实例的应用程序不断创build和删除密钥。

一个月后,我结束了一个mem_fragmentation_ratio> 1.30。 这会影响该服务器上Redis的内存占用情况:

~$ redis-cli info memory # Memory used_memory:7711297480 used_memory_human:7.18G used_memory_rss:10695098368 used_memory_peak:11301744128 used_memory_peak_human:10.53G used_memory_lua:95232 mem_fragmentation_ratio:1.39 mem_allocator:jemalloc-3.6.0 

如果我重新启动Redis服务并从AOF重新加载,则mem_fragmentation_ratio会回到可接受的级别(1.06):

 ~$ redis-cli info memory # Memory used_memory:7493466968 used_memory_human:6.98G used_memory_rss:7924920320 used_memory_peak:8279112992 used_memory_peak_human:7.71G used_memory_lua:91136 mem_fragmentation_ratio:1.06 mem_allocator:jemalloc-3.6.0 

回收Redis正在影响我们的应用程序(即使我们在从属程序重新启动后使用Sentinel故障切换执行此操作)。

有没有另一种方法来减lessmem_fragmentation_ratio,就像我可以安排非高峰的“碎片整理”过程?