Redis – Lost Persistence in Long Term Without TTL

configurationredis

Our keys are lost in some time and we cannot find the problem.

We are using AOF and RDB at the sametime with configs below:

RDB:

save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb

AOF:

appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

As you can see there is no fancy… all are redis defaults.

I have tried to create keys and reboot the server. At this circumstances the keys still. I couldn't determine when keys are lost or why? The log files are not helpful cause I don't know what to query in logs or when.

All I know is my keys are lost at a time interval about one month.

How can I debug this kind of problem in redis?

Best Answer

Preface: keys in Redis do not get deleted, unless explicitly requested or when the server is configured with an eviction policy (and RAM is pressured).

Regrettably, the most common cause for missing keys is security, or rather the lack of it. Script kids, leet haxors and regular bad guys take advantage of unprotected servers and cause all kinds of havoc. The first thing you need to do is ensure that the server is protected properly (i.e. is configured with a password and is not exposed to the world). For more details refer to https://redis.io/topics/security

After ruling out attacks and eviction policy configuration, the only remaining explanation is a rogue piece of code. From the server's side, you can try tracking this behavior using either the MONITOR command or by configuring keyspace events and subscribing to the relevant messages.