cachex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 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 cachex talks to Redis-compatible caches (Redis, Valkey, KeyDB, Dragonfly) and classifies their commands by risk. Redis has no read-only transactions, so the classifier is the safety layer: without --write only commands known to be reads are sent.

Index

Constants

This section is empty.

Variables

View Source
var InfoSections = []string{"server", "clients", "memory", "persistence", "threads", "stats", "replication", "cpu",
	"commandstats", "latencystats", "sentinel", "cluster", "modules", "keyspace", "errorstats", "keysizes",
	"all", "default", "everything"}

InfoSections are the sections INFO accepts.

Functions

func Classify

func Classify(args []string) driver.Verdict

Classify rates a raw command. Unknown commands are writes.

func CmdErr

func CmdErr(err error) error

CmdErr maps a redis error to a komando error code.

func Info

func Info(ctx context.Context, c *redis.Client, section string) (map[string]map[string]string, error)

Info returns the INFO reply as sections of key/value pairs.

func Keys

func Keys(ctx context.Context, c *redis.Client, pattern string, limit int) (keys []string, more bool, err error)

Keys lists keys matching pattern with SCAN (never KEYS), up to limit.

func Open

func Open(ctx context.Context, t driver.Target, password string, dial DialFunc, timeout time.Duration) (*redis.Client, error)

Open connects to a redis conn and checks it answers.

func Quote

func Quote(s string) string

Quote shows s on one line: as it is when that is unambiguous, else in double quotes with \n, \t, \" and \xNN escapes.

func ReplyText

func ReplyText(v any) string

ReplyText renders a reply from Run like redis-cli does.

func Rules

func Rules() []driver.Rule

Rules lists the rules Classify can report.

func Run

func Run(ctx context.Context, c *redis.Client, args []string) (any, error)

Run sends a raw command and converts the reply to JSON-safe values.

Types

type DialFunc

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialFunc opens a TCP connection, possibly through an SSH host.

type Summary

type Summary struct {
	Version        string           `json:"version"`
	Mode           string           `json:"mode,omitempty"`
	Role           string           `json:"role"`
	UptimeSeconds  int64            `json:"uptime_seconds"`
	UsedMemory     int64            `json:"used_memory_bytes"`
	MaxMemory      int64            `json:"maxmemory_bytes"` // 0 = no limit
	EvictionPolicy string           `json:"eviction_policy,omitempty"`
	Clients        int64            `json:"connected_clients"`
	Keys           map[string]int64 `json:"keys"`     // per database: db0 -> count
	Expires        map[string]int64 `json:"expires"`  // keys with a time to live, per database
	Hits           int64            `json:"hits"`     // keyspace hits since start
	Misses         int64            `json:"misses"`   // keyspace misses since start
	HitRate        *float64         `json:"hit_rate"` // hits / (hits + misses); null before any read
}

Summary is the INFO reply boiled down to what people check first.

func Summarize

func Summarize(info map[string]map[string]string) Summary

Summarize picks the summary out of parsed INFO sections.

type Value

type Value struct {
	Key       string `json:"key"`
	Type      string `json:"type"`
	TTL       *int64 `json:"ttl_seconds"` // null = no expiry
	Size      int64  `json:"size"`        // bytes for strings, items for collections
	Value     any    `json:"value"`
	Truncated bool   `json:"truncated,omitempty"`
}

Value is a key with its type, time to live and (part of) its content.

func Get

func Get(ctx context.Context, c *redis.Client, key string, limit int64, maxBytes int) (*Value, error)

Get reads a key of any type. Collections return at most limit items.

func (*Value) Text

func (v *Value) Text() string

Text shows a key for people: what it is, when it expires, and its content one item per line.

Jump to

Keyboard shortcuts

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