Documentation
¶
Overview ¶
Package redisengine runs an in-process Redis-protocol server (miniredis) on an allocator-provided or ephemeral port.
Index ¶
- Constants
- Variables
- func DecodeRDB(mr *miniredis.Miniredis, data []byte) error
- func DumpKeyspace(mr *miniredis.Miniredis) ([]byte, error)
- func EncodeRDB(mr *miniredis.Miniredis) ([]byte, error)
- func LoadKeyspace(mr *miniredis.Miniredis, data []byte) error
- func ValidateAccessString(s string) error
- type Engine
- func (e *Engine) Addr() string
- func (e *Engine) Close()
- func (e *Engine) ExportRDB() ([]byte, error)
- func (e *Engine) ImportRDB(data []byte) error
- func (e *Engine) RequireAuth(password string)
- func (e *Engine) Restore(data []byte) error
- func (e *Engine) SetUserAccess(users []UserAccess) error
- func (e *Engine) Settings() Settings
- func (e *Engine) Snapshot() ([]byte, error)
- func (e *Engine) Tune(s Settings) error
- type Gate
- type Settings
- type UserAccess
Constants ¶
const ( PolicyNoEviction = "noeviction" PolicyAllKeysLRU = "allkeys-lru" PolicyVolatileLRU = "volatile-lru" PolicyAllKeysLFU = "allkeys-lfu" PolicyVolatileLFU = "volatile-lfu" PolicyAllKeysRandom = "allkeys-random" PolicyVolatileRandom = "volatile-random" PolicyVolatileTTL = "volatile-ttl" )
Eviction policies accepted by maxmemory-policy.
Variables ¶
var ErrBadRDB = errors.New("invalid RDB data")
ErrBadRDB is returned when RDB data is malformed.
var ErrBadSnapshot = errors.New("invalid engine snapshot data")
ErrBadSnapshot is returned when snapshot data cannot be decoded.
var ErrInvalidSettings = errors.New("invalid engine settings")
ErrInvalidSettings is returned by Tune for values Redis would reject.
var ErrUnsupportedRDB = errors.New("unsupported RDB content")
ErrUnsupportedRDB is returned for RDB content the engine cannot represent.
Functions ¶
func DumpKeyspace ¶
DumpKeyspace is Snapshot for a bare miniredis server. A nil server yields nil.
func LoadKeyspace ¶
LoadKeyspace is Restore for a bare miniredis server.
func ValidateAccessString ¶
ValidateAccessString reports whether SetUserAccess can enforce the access string.
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 ¶
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 ¶
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 (*Engine) Close ¶
func (e *Engine) Close()
Close stops the server and releases its allocated port. Nil-safe and idempotent.
func (*Engine) ExportRDB ¶
ExportRDB serialises the keyspace as a Redis RDB file. Plain data is written as version 9; streams (with their consumer groups and pending entries) raise it to 11 and per-field hash TTLs to 12, the first versions that can carry them. Streams are cut into listpack nodes following stream-node-max-bytes and stream-node-max-entries.
func (*Engine) ImportRDB ¶
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) RequireAuth ¶
RequireAuth makes the server demand password and remembers it so in-process operations (snapshots, RDB import and export) can authenticate.
func (*Engine) Restore ¶
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) SetUserAccess ¶
func (e *Engine) SetUserAccess(users []UserAccess) error
SetUserAccess enforces the users' access strings: connections authenticate with AUTH, and each command, key and channel is checked against the authenticated user's rules (NOPERM on denial). Connections that never authenticate act as user "default", which is unrestricted unless listed. It installs the server's pre-command hook, so it cannot be combined with Tune. An empty list removes enforcement.
func (*Engine) Settings ¶
Settings reports what Tune last applied, or DefaultSettings for an untuned engine.
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.
type Settings ¶
type Settings struct {
RedisVersion string
Policy string
NotifyKeyspaceEvents string
MaxMemory int64
Timeout time.Duration
SlowlogLogSlowerThan time.Duration
LFULogFactor int
LFUDecayTime int
StreamNodeMaxBytes int
StreamNodeMaxEntries int
Databases int
SlowlogMaxLen int
MaxMemoryClients int
ActiveDefrag bool
LazyfreeLazyEviction bool
LazyfreeLazyExpire bool
LazyfreeLazyUserDel bool
LazyfreeLazyUserFlsh bool
}
Settings are the runtime parameters Tune applies to an engine; DefaultSettings holds the Redis defaults.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns Redis's stock configuration: no memory limit, noeviction, no keyspace events.
type UserAccess ¶
UserAccess is one ACL user: the AUTH password and the Redis ACL rule string (for example "on ~app:* &* +@read") enforced on that user's connections.