mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-21 06:59:24 +08:00
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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user