kstyrc / embedded-redis

Redis embedded server for Java integration testing
840 stars 368 forks source link

Is it possible to save to disk? #72

Closed yadavan88 closed 7 years ago

yadavan88 commented 7 years ago

I am trying to use this embedded-redis as a temporary storage for a small device, if I there is no internet connectivity. When the connection is back, the data is uploaded to server. But with this, if the device is rebooted, the data will be lost. Is it possible to save the data to the disk and delete only on demand ?

casidiablo commented 7 years ago

It is possible. Take a look at the RedisServerBuilder#configFile() method. You can use it to start the server with a custom config file, which in turn lets you configure redis itself (including its persistence settings and all of that).

yadavan88 commented 7 years ago

Thanks for the help. I did try that and it is working fine. Posting the sample here if anyone else is looking for the same.

RedisServer redisServer = RedisServer.builder()
                    .redisExecProvider(customProvider)
                    .port(6000)
                    .setting("daemonize no")
                    .setting("databases 5")
                    .setting("save 300 1")
                    .setting("dbfilename rbridgedump.rdb")
                    .setting("dir /home/Desktop")
                    .setting("maxheap 128M")
                    .build();