Documentation
¶
Overview ¶
Package shared is the state several `flowi serve` instances can share through a Valkey (or Redis) server: which schedule tick has been taken and how a run ended, so that GET /runs/<id> works on any instance.
Everything in it is optional and fails open. The Valkey client is a small RESP client over the standard library; when the server cannot be reached it reports ErrUnavailable at once for a quiet period instead of waiting on every call, so a down cache never slows a run or a tick.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // returned at once during the quiet period that follows a failure. ErrUnavailable = errors.New("the shared store is unavailable") // ErrTooLarge is returned for a value above maxValue. ErrTooLarge = errors.New("the value is too large for the shared store") )
Errors a Store can return.
Functions ¶
This section is empty.
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a Store in this process's memory: for tests, and for running the same code paths without a server.
type Records ¶
type Records struct{ Store Store }
Records publishes run records in a Store; it is a runs.SharedRecords.
func (Records) LoadRecord ¶
LoadRecord implements runs.SharedRecords.
type Store ¶
type Store interface {
// Claim reports whether the caller is the first to claim key; the claim
// lapses after ttl. It is how one instance out of several takes a
// schedule tick.
Claim(ctx context.Context, key string, ttl time.Duration) (bool, error)
// Put stores value under key for ttl.
Put(ctx context.Context, key string, value []byte, ttl time.Duration) error
// Get returns the value under key; ok is false when there is none.
Get(ctx context.Context, key string) (value []byte, ok bool, err error)
// Close releases the store's connection.
Close() error
}
Store is the shared state of serve instances. Implementations are safe for concurrent use.
type Valkey ¶
type Valkey struct {
// contains filtered or unexported fields
}
Valkey is a Store on a Valkey or Redis server, over RESP2.
It keeps one connection, opened on first use and reopened once if a call finds it closed. After a failure that a fresh connection does not cure it returns ErrUnavailable for quietPeriod without dialing.
func NewValkey ¶
func NewValkey(cfg ValkeyConfig) (*Valkey, error)
NewValkey checks the configuration. It does not connect: a server that is down at start must not stop serve from starting.
type ValkeyConfig ¶
type ValkeyConfig struct {
Addr string // host:port
Password string // sent with AUTH when not empty; never logged
TLS bool
Prefix string // put before every key, so workspaces do not meet
Timeout time.Duration // per connect and per command; default 2s
Logger *slog.Logger
Now func() time.Time // for the quiet period; default time.Now
}
ValkeyConfig configures a Valkey store.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sharedtest is a small in-process stand-in for a Valkey or Redis server, for tests of code that talks to one.
|
Package sharedtest is a small in-process stand-in for a Valkey or Redis server, for tests of code that talks to one. |