Using the express-session package I set my max age to 5 minutes and sure enough inside Redis the key was deleted after the time was up.
However 20 or 30 minutes later when I looked inside appendonly.aof a reference to the key still existed. Is this reference ever removed and if so how long until the removal takes place?
set
$37
sess:d1tyG1Bai8szCzFzanQINbglhRPGpzmq
$132
{"cookie":{"originalMaxAge":300000,"expires":"2021-02-01T01:42:10.054Z","secure":false,"httpOnly":true,"path":"/","sameSite":"lax"}}
*3
$9
PEXPIREAT
$37
sess:d1tyG1Bai8szCzFzanQINbglhRPGpzmq
$13
1612143730056
*2
$3
DEL
$37
sess:d1tyG1Bai8szCzFzanQINbglhRPGpzmq
*3
$3
Comment From: bpo
@333one the AOF is a log of all events that happened. Periodically the AOF is "rewritten", a process which condenses the log by collapsing events like modifications and deletes to store only the final value. So - you'll see the reference to the deleted key removed after the next rewrite.
Rewrite timing depends on the database configuration - usually based on some multiple of growth. You can trigger a rewrite manually with the BGREWRITEAOF command.
Comment From: itamarhaber
Hello @333one
Adding to @bpo's answer, you can find more information about Redis' AOF persistence mechanism at https://redis.io/topics/persistence#append-only-file.
Closing this question as answered - please feel free to reopen if needed.