valkey

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

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

func New(s store, cfg Config) *Sink

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) Events

func (sk *Sink) Events(ctx context.Context, q usage.EventQuery) ([]usage.Event, error)

Events returns raw events matching q, newest-first, capped at q.Limit.

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

TimeSeries buckets the matching events into time series via usage.Bucketize.

func (*Sink) Write

func (sk *Sink) Write(ev usage.Event) error

Write marshals ev to JSON and stores it under a TTL-bounded key.

Jump to

Keyboard shortcuts

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