valkey

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 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 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) Count added in v0.11.1

func (sk *Sink) Count(ctx context.Context, q usage.EventQuery, limit int) (int64, error)

Count returns how many events Events would match, up to limit.

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) Facet added in v0.11.1

func (sk *Sink) Facet(ctx context.Context, q usage.FacetQuery) ([]usage.FacetValue, error)

Facet counts q.Dim's values over the matching events via usage.TopValues.

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