Take expiry into account when creating snashot and AOF preamble. If the key is already expired when snapshot is taken, it will not be persisted. If the key is expired when loading a snapshot/preamble, it will not be restored.

This commit is contained in:
Kelvin Mwinuka
2024-03-12 21:35:39 +08:00
parent f27a0dda79
commit 52646d1564
10 changed files with 114 additions and 35 deletions

View File

@@ -125,6 +125,15 @@ func NewServer(opts Opts) *Server {
server.KeyUnlock(ctx, key)
return nil
},
SetExpiry: func(key string, expireAt time.Time) error {
ctx := context.Background()
if _, err := server.KeyLock(ctx, key); err != nil {
return err
}
server.SetExpiry(ctx, key, expireAt, false)
server.KeyUnlock(ctx, key)
return nil
},
})
// Set up standalone AOF engine
server.AOFEngine = aof.NewAOFEngine(
@@ -144,6 +153,15 @@ func NewServer(opts Opts) *Server {
server.KeyUnlock(ctx, key)
return nil
}),
aof.WithSetExpiryFunc(func(key string, expireAt time.Time) error {
ctx := context.Background()
if _, err := server.KeyLock(ctx, key); err != nil {
return err
}
server.SetExpiry(ctx, key, expireAt, false)
server.KeyUnlock(ctx, key)
return nil
}),
aof.WithHandleCommandFunc(func(command []byte) {
_, err := server.handleCommand(context.Background(), command, nil, true)
if err != nil {