persistence

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package persistence ties snapshots and the AOF to the engine: it loads data at startup, applies the "save" rules, runs BGSAVE / BGREWRITEAOF and flushes everything at shutdown. It implements command.Persister.

Index

Constants

This section is empty.

Variables

View Source
var ErrBgSaveInProgress = errors.New("ERR Background save already in progress")

ErrBgSaveInProgress is returned by Save/BgSave while a background save runs.

Functions

This section is empty.

Types

type Manager

type Manager struct {

	// CronInterval is how often save rules and auto AOF rewrite are checked.
	CronInterval time.Duration
	// contains filtered or unexported fields
}

Manager implements command.Persister.

func Setup

func Setup(e *command.Engine) (*Manager, error)

Setup loads the dataset (the AOF when appendonly is on and the file exists, otherwise the snapshot), opens the AOF and registers it as a propagator, sets e.Persist and starts the save-rules goroutine. Call it after command.New and before serving clients.

func (*Manager) AOF

func (m *Manager) AOF() *aof.AOF

AOF returns the open AOF, or nil when appendonly is off.

func (*Manager) AOFPath

func (m *Manager) AOFPath() string

AOFPath is dir/appendfilename.

func (*Manager) BgRewriteAOF

func (m *Manager) BgRewriteAOF() error

BgRewriteAOF compacts the AOF in the background (BGREWRITEAOF).

func (*Manager) BgSave

func (m *Manager) BgSave() error

BgSave starts a snapshot in the background (BGSAVE). The keyspace is only locked while it is serialised into memory; the disk write runs unlocked.

func (*Manager) Close

func (m *Manager) Close(save bool) error

Close stops background work and makes everything durable: waits for running saves/rewrites, writes a final snapshot if save is true, and flushes, fsyncs and closes the AOF. Call it at shutdown after the server stopped accepting commands.

func (*Manager) Info

func (m *Manager) Info() [][2]string

Info returns the persistence section of INFO.

func (*Manager) LastSave

func (m *Manager) LastSave() time.Time

LastSave is the time of the last successful snapshot.

func (*Manager) Save

func (m *Manager) Save() error

Save writes a snapshot synchronously (SAVE). It takes DB.LockAll itself, so it must not be called while holding shard locks.

func (*Manager) SnapshotPath

func (m *Manager) SnapshotPath() string

SnapshotPath is dir/dbfilename.

Directories

Path Synopsis
Package aof implements the append-only file: every write command is appended in RESP form (the same bytes a client sends), and replaying the file through the dispatcher rebuilds the dataset.
Package aof implements the append-only file: every write command is appended in RESP form (the same bytes a client sends), and replaying the file through the dispatcher rebuilds the dataset.
Package snapshot implements cache-boy's binary point-in-time dump (the equivalent of Redis' RDB file).
Package snapshot implements cache-boy's binary point-in-time dump (the equivalent of Redis' RDB file).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL