Reputation: 143
I searched for this a lot but couldn't find anything helpful. Is there any way to reset a key to a default value (maybe by deleting and setting it again) on redis server restart?
Or somehow to remove persistence on particular keys, or make an expire time until server restart?
Upvotes: 1
Views: 1470
Reputation: 49942
TL;DR No.
There is no way to set a default value for a key in Redis except in your code.
There is no way to disable persistence only for a subset of keys - persistence is an all or nothing configuration of the server.
There is no way to make certain keys expire on server restart - TTLs are deterministic and persisted across restarts.
One possible way to have this is to spin two Redis servers, one with persistency enabled and the other without it, and use both in the application per key "type. Alternatively, you can script the initialization into the server's bootstrap, or perhaps monitor it somehow in your app or external to it.
Upvotes: 1