Reputation: 13298
I'm using redis with my spring boot application using jedis, spring-data-redis. I want to control the persistence mechanism of redis in the following way.
In one case I want the data to be persisted into the dump file, so that on restart of redis server that data should be accessible.
In second case I want to keep the data just into redis in-memory and accessible to the application till the redis server is running and should be discarded on redis server restart.
I've read the redis data persistence policies and it seems that it allows storing the data on some time intervals, but is there any way I can control the persistence only programmatically & not use the time interval based persistence mechanism
Upvotes: 0
Views: 1336
Reputation: 13298
I found solution to this issue. So the changes I made to control the persistence only programmatically are as below
Comment all the save lines from redis configuration file. This will stop redis's default time/operations based persistence mechanism.
Then call save() or bgsave() whenever you want to persist the data on disc.
So using the RedisTemplate you can call
redisTemplate.getConnectionFactory().getConnection().save();
and this will persist the changes on disc.
For my requirement, I'm passing a shouldPersist
flag to my repository methods to decide whether to persist the data or not. If the data is not persisted using save
or bgsave
it will be discarded on server restart. Which is what I want for some of my scenarios.
Upvotes: 1