简体   繁体   English

在Linux上重新启动后如何配置Redis以保留数据?

[英]How to configure Redis to persist data after reboot on Linux?

I installed Redis on Ubuntu 16.04. 我在Ubuntu 16.04上安装了Redis。 I couldn't find Redis directory nor redis.conf file (tried with: sudo find redis.conf ). 我找不到Redis目录或redis.conf文件(尝试使用: sudo find redis.conf )。

My application depends on some data pulled from third party APIs. 我的应用程序依赖于从第三方API提取的一些数据。 I store the (processed) data in Redis. 我将(处理后的)数据存储在Redis中。 My problem is, after reboot I lose the data. 我的问题是,重新启动后,我丢失了数据。 I guess I need to specify in config file that the data should be persisted on reboot, but I couldn't find the config file. 我想我需要在配置文件中指定重启后应该保留数据,但是我找不到配置文件。 Do I need to create the config file? 我需要创建配置文件吗? Are there some templates to use? 有没有要使用的模板? My goal is just to have the data persisted after reboot. 我的目标只是在重新启动后保留数据。

Thank you! 谢谢!

Use dpkg -L | grep redis.conf 使用dpkg -L | grep redis.conf dpkg -L | grep redis.conf to find config file path. dpkg -L | grep redis.conf查找配置文件路径。 It should be located at /etc/redis/redis.conf as I know. 据我所知,它应该位于/etc/redis/redis.conf中。

Redis has 2 methods for persistense: Snapshotting and Append-only file : Redis有两种持久性方法: SnapshottingAppend-only file

  • Snapshotting will be enabled by adding (or uncommenting) save XY in config file. 通过在配置文件中添加(或取消注释) save XY可以启用Snapshotting功能。 It means Redis will automatically dump the dataset to disk every X seconds if at least Y keys changed. 这意味着如果至少更改了Y键,Redis将每隔X秒自动将数据集转储到磁盘。 There could be more than one save options in config file. 配置文件中可能有多个save选项。

  • Append-only file will be enabled by adding (or uncommenting) appendonly yes in config file 通过在配置文件中添加(或取消注释) appendonly yes可以启用Append-only file appendonly yes文件

you should turn on the rdb or aof. 您应该打开rdb或aof。

see https://redis.io/topics/persistence 参见https://redis.io/topics/persistence

Add this to the config file. 将此添加到配置文件。

appendonly yes appendonly是

This will append data as you store new data. 存储新数据时,这将追加数据。 This enables durability. 这实现了耐久性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM