cachevalkey

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cachevalkey adapts valkey-go clients to the cache backend contract. Clients remain caller-owned; configure their TLS, retries and deadlines. Writes use relative server expiry to StaleAt, with a 1 ms minimum; clock skew, transport latency and provider retry semantics remain observable. Constructors do not ping/open/close clients. Standalone is the documented supported topology.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend implements cache.Backend with valkey-go.

func New

func New(config Config) (*Backend, error)

New validates config and constructs a Valkey backend.

func (*Backend) Delete

func (b *Backend) Delete(ctx context.Context, key string) (bool, error)

Delete removes key and reports whether Valkey deleted it.

func (*Backend) Get

func (b *Backend) Get(ctx context.Context, key string) (cache.Record, bool, error)

Get reads and validates one bounded wire record. The Lua preflight rejects oversized string values before GET; malformed/wrong-type data remains an error. Raw backend reads can outlive local StaleAt due to server/clock timing.

func (*Backend) Set

func (b *Backend) Set(
	ctx context.Context,
	key string,
	record cache.Record,
	condition cache.Condition,
) (bool, error)

Set atomically writes a record with its stale deadline as relative expiry. Non-positive remaining TTL is rejected; positive sub-millisecond TTL uses 1 ms. Conditions test server key existence, not a record-version fence.

func (*Backend) SetIfOwned

func (b *Backend) SetIfOwned(
	ctx context.Context,
	key string,
	record cache.Record,
	guard cache.OwnershipGuard,
) error

SetIfOwned atomically compares an active Valkey lease hash and publishes the record. A missing, expired, or superseded lease returns ErrOwnershipLost. The guard must describe a compatible hash on the same supported standalone deployment. Tokens are compared for equality, not numeric ordering. This neither acquires/renews a lease nor fences durable non-cache side effects.

type Config

type Config struct {
	// Client is caller-owned; configure concurrency, TLS, retries and timeouts externally.
	Client valkeyclient.CommandClient
	// Clock is retained for relative TTL calculation; clock skew affects server expiry.
	Clock cache.Clock
	// MaxRecordSize is the positive wire-byte ceiling, including the 21-byte envelope header.
	MaxRecordSize int
}

Config supplies the native client, clock, and maximum wire record size.

Jump to

Keyboard shortcuts

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