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

command

package
v2.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package command implements BoltCache's Redis-compatible command set. A single Engine executes commands for every transport (RESP, the legacy text protocol, REST and Lua scripts), so they all behave identically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWrite

func IsWrite(name string) bool

IsWrite reports whether the named command modifies data.

func Names

func Names() []string

Names returns all command names, sorted.

func WriteMessage

func WriteMessage(w resp.Writer, channel, pattern, message string)

WriteMessage encodes a pub/sub message the way RESP2 subscribers expect.

Types

type Authenticator

type Authenticator interface {
	Enabled() bool
	Check(password string) bool
}

Authenticator validates AUTH passwords (API tokens).

type Config

type Config struct {
	// Auth validates AUTH; nil (and no Passwords) disables authentication.
	Auth Authenticator
	// Passwords is a static alternative to Auth.
	Passwords []string
	// LuaEnabled enables EVAL/EVALSHA/SCRIPT.
	LuaEnabled bool
	// PubSubEnabled enables PUBLISH/SUBSCRIBE.
	PubSubEnabled bool
	// ScriptTimeout aborts scripts running longer than this (default 5s).
	ScriptTimeout time.Duration
	// Version is reported by INFO and HELLO.
	Version string
}

Config controls optional engine features.

type Engine

type Engine struct {

	// Optional hooks used by INFO/SAVE; set before serving.
	Persister   *cache.Persister
	ClientCount func() int64
	// contains filtered or unexported fields
}

Engine executes commands against a cache.

func New

func New(c *cache.BoltCache, hub *pubsub.Hub, cfg Config) *Engine

New creates an engine.

func (*Engine) AuthRequired

func (e *Engine) AuthRequired() bool

AuthRequired reports whether clients must authenticate.

func (*Engine) Cache

func (e *Engine) Cache() *cache.BoltCache

Cache returns the underlying cache.

func (*Engine) CheckPassword

func (e *Engine) CheckPassword(p string) bool

CheckPassword validates p in constant time.

func (*Engine) CloseSession

func (e *Engine) CloseSession(s *Session)

CloseSession releases resources held by s (subscriptions).

func (*Engine) Exec

func (e *Engine) Exec(s *Session, argv [][]byte, w resp.Writer)

Exec runs one command (argv[0] is the name) and writes its reply to w.

func (*Engine) ExecPipeline added in v2.1.0

func (e *Engine) ExecPipeline(s *Session, cmds [][]string, w resp.Writer)

ExecPipeline runs commands received together (a client pipeline). Consecutive single-key commands whose keys live in the same shard run under one lock acquisition instead of one each. Without this, many clients pipelining commands at one hot key (a leaderboard, a counter, a queue) spend most of their time contending for that shard's lock. Results and semantics are identical to calling ExecStrings for each command.

func (*Engine) ExecStrings

func (e *Engine) ExecStrings(s *Session, args []string, w resp.Writer)

ExecStrings is Exec for already converted arguments.

func (*Engine) Hub

func (e *Engine) Hub() *pubsub.Hub

Hub returns the pub/sub hub.

func (*Engine) Info

func (e *Engine) Info(section string) string

Info renders the INFO text for the given section ("" or "all" for every section).

func (*Engine) NewSession

func (e *Engine) NewSession(addr string, sub pubsub.Subscriber) *Session

NewSession creates a session; it's pre-authenticated when no password is configured.

func (*Engine) Stats

func (e *Engine) Stats() (commands, rejected uint64)

Stats about command processing.

type Session

type Session struct {
	ID            int64
	Name          string
	Addr          string
	Authenticated bool
	// Subscriber receives pub/sub messages; nil when the transport doesn't
	// support subscriptions.
	Subscriber pubsub.Subscriber
	// Close is set when the client asked to close the connection (QUIT).
	Close bool
	// contains filtered or unexported fields
}

Session holds per-connection state.

func (*Session) Subscriptions

func (s *Session) Subscriptions() int

Subscriptions returns the number of channel and pattern subscriptions.

Jump to

Keyboard shortcuts

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