Documentation
¶
Overview ¶
Package valkey is a TTL-bounded usage Sink + Reader backed by pkg/kv. It is a hot-window / live-tail cache — NOT long-term history. Events expire automatically via the TTL set on each key; ClickHouse owns history.
Expected kv ops per Write: 1 × Set (one key, JSON value, TTL-bounded). Expected kv ops per Events/Summary query: 1 × Range (prefix scan).
All keys share the hash-tag "{u}" so every key touched in a Range scan maps to the same Redis Cluster slot and cluster-mode Range works correctly. Key schema: usagevk:{u}:<20-digit-zero-padded-unixnano>:<request_id> Lexical order of the timestamp portion approximates time order, but we sort in Go after decode — do not rely on store ordering.
Index ¶
- type Config
- type Sink
- func (sk *Sink) Events(ctx context.Context, q usage.EventQuery) ([]usage.Event, error)
- func (sk *Sink) Summary(ctx context.Context, q usage.SummaryQuery) (usage.SummaryResult, error)
- func (sk *Sink) TimeSeries(ctx context.Context, q usage.TimeSeriesQuery) (usage.TimeSeriesResult, error)
- func (sk *Sink) Write(ev usage.Event) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// TTL is the per-event key lifetime. Defaults to 24h when zero.
TTL time.Duration
// KeyPrefix is the Redis key prefix (without the hash-tag). Defaults
// to "usagevk". Override in tests that share a store.
KeyPrefix string
}
Config controls runtime behaviour.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink is the valkey backend. It implements usage.Sink and usage.Reader.
func New ¶
New constructs a Sink. s must implement the narrow store interface (any kv.Store satisfies it). cfg fields are optional; zero values use defaults.
func (*Sink) Summary ¶
func (sk *Sink) Summary(ctx context.Context, q usage.SummaryQuery) (usage.SummaryResult, error)
Summary returns aggregated rows grouped by q.GroupBy.
func (*Sink) TimeSeries ¶
func (sk *Sink) TimeSeries(ctx context.Context, q usage.TimeSeriesQuery) (usage.TimeSeriesResult, error)
TimeSeries buckets the matching events into time series via usage.Bucketize.