Help us shape the future of Go! Take the 2026 Go Developer Survey

redisengine

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package redisengine runs an in-process Redis-protocol server (miniredis) on an allocator-provided or ephemeral port.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRDB = errors.New("invalid RDB data")

ErrBadRDB is returned when RDB data is malformed.

View Source
var ErrBadSnapshot = errors.New("invalid engine snapshot data")

ErrBadSnapshot is returned when snapshot data cannot be decoded.

View Source
var ErrUnsupportedRDB = errors.New("unsupported RDB content")

ErrUnsupportedRDB is returned for RDB content the engine cannot represent.

Functions

func DecodeRDB

func DecodeRDB(mr *miniredis.Miniredis, data []byte) error

DecodeRDB is ImportRDB for a bare miniredis server.

func DumpKeyspace

func DumpKeyspace(mr *miniredis.Miniredis) ([]byte, error)

DumpKeyspace is Snapshot for a bare miniredis server. A nil server yields nil.

func EncodeRDB

func EncodeRDB(mr *miniredis.Miniredis) ([]byte, error)

EncodeRDB is ExportRDB for a bare miniredis server.

func LoadKeyspace

func LoadKeyspace(mr *miniredis.Miniredis, data []byte) error

LoadKeyspace is Restore for a bare miniredis server.

Types

type Engine

type Engine struct {
	Mini *miniredis.Miniredis

	// Front relays clients to Mini behind an admit check; nil for ungated engines.
	Front *sgfilter.Proxy
	// Gate decides Front's admissions; deny-all until Set.
	Gate          *Gate
	Host          string
	Port          int
	AllocatedPort int
	// contains filtered or unexported fields
}

Engine is a running in-process Redis-protocol server.

func Start

func Start(alloc *portalloc.Allocator, label string) (*Engine, error)

Start launches a server. With a non-nil allocator the port is acquired from it under label and bound on all interfaces; otherwise an ephemeral loopback port is used.

func StartGated

func StartGated(alloc *portalloc.Allocator, label string) (*Engine, error)

StartGated is Start with the client-facing port served by a relay in front of a loopback-only server, so Gate can refuse clients. The allocator port (or an ephemeral loopback one) is the relay's.

func StartTLS

func StartTLS(alloc *portalloc.Allocator, label string, cfg *tls.Config) (*Engine, error)

StartTLS is Start serving TLS with cfg; a nil cfg serves plaintext.

func (*Engine) Addr

func (e *Engine) Addr() string

Addr returns the connectable host:port.

func (*Engine) Close

func (e *Engine) Close()

Close stops the server and releases its allocated port. Nil-safe and idempotent.

func (*Engine) ExportRDB

func (e *Engine) ExportRDB() ([]byte, error)

ExportRDB serialises the keyspace as a Redis RDB file (version 9). Streams are not representable and fail the export; per-field hash TTLs are dropped because RDB 9 cannot carry them.

func (*Engine) ImportRDB

func (e *Engine) ImportRDB(data []byte) error

ImportRDB replaces the keyspace with the contents of an RDB file. Strings, lists, sets, sorted sets and hashes in their plain encodings are supported (with LZF and integer string encodings); compact ziplist, listpack and intset encodings, streams and modules fail with ErrUnsupportedRDB. The keyspace is left untouched on error.

func (*Engine) Restore

func (e *Engine) Restore(data []byte) error

Restore loads a blob produced by Snapshot into the engine, overwriting existing keys of the same name. Empty data is a no-op.

func (*Engine) Snapshot

func (e *Engine) Snapshot() ([]byte, error)

Snapshot serialises the keyspace (strings, hashes, lists, sets, sorted sets, streams, key and hash-field TTLs) into a gzip'd opaque blob. Returns nil when the engine holds no keys. HyperLogLog keys and stream consumer groups are not captured.

type Gate

type Gate struct {
	// contains filtered or unexported fields
}

Gate holds a connection check installed after the engine starts, once its owner can name the target; until then every client is refused.

func (*Gate) Admit

func (g *Gate) Admit(remote net.Addr) bool

Admit implements sgfilter.Admitter.

func (*Gate) Set

func (g *Gate) Set(a sgfilter.Admitter)

Set installs the check.

Jump to

Keyboard shortcuts

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