valkey

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 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

Index

Constants

This section is empty.

Variables

View Source
var ErrCircuitOpen = errors.New("valkey: circuit breaker open")

ErrCircuitOpen is returned when the circuit breaker is open and requests are being shed to protect Valkey from cascading failures.

Functions

func LoadMergedManagedManifest

func LoadMergedManagedManifest(ctx context.Context, c *Client, ref string, fileManifest *proxy.RouteManifest) (*proxy.RouteManifest, error)

LoadMergedManagedManifest builds the effective route manifest for a managed pod: start from fileManifest (typically SUPATYPE_MANIFEST_PATH), overlay routing fields from tenant:{ref}:config, then overlay tenant:{ref}:manifest when present.

func RouteManifestKey

func RouteManifestKey(ref string) string

RouteManifestKey returns the Valkey key for a full route manifest override (same JSON shape as .supatype/manifest.json).

Types

type Client

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

Client wraps a valkey-go client with a simple circuit breaker. After cbFailThreshold consecutive errors the circuit opens and all requests return ErrCircuitOpen immediately. After cbOpenDuration the circuit enters half-open state: one probe request is allowed through.

func New

func New(addr string) (*Client, error)

New creates a Client connected to addr (e.g. "127.0.0.1:6379").

func (*Client) Close

func (c *Client) Close()

Close shuts down the underlying Valkey client.

func (*Client) Del

func (c *Client) Del(ctx context.Context, keys ...string) error

Del deletes one or more keys.

func (*Client) GetBytes

func (c *Client) GetBytes(ctx context.Context, key string) ([]byte, error)

GetBytes fetches a raw byte value by key.

func (*Client) GetTenantConfig

func (c *Client) GetTenantConfig(ctx context.Context, ref string) (*TenantConfig, error)

GetTenantConfig fetches the TenantConfig for ref from Valkey. Key pattern: tenant:{ref}:config

Returns ErrCircuitOpen if the circuit breaker is open. Returns (nil, nil) when the key is absent (cache miss). Returns (nil, err) if the value cannot be decoded.

func (*Client) ScanPage

func (c *Client) ScanPage(ctx context.Context, cursor uint64, pattern string, count int) (keys []string, next uint64, err error)

ScanPage scans keys matching pattern starting at cursor. count is a hint per page.

func (*Client) SetBytes

func (c *Client) SetBytes(ctx context.Context, key string, value []byte, ttlSeconds int) error

SetBytes stores raw bytes with an optional TTL (seconds). ttlSeconds <= 0 means no expiry.

func (*Client) TTLSeconds

func (c *Client) TTLSeconds(ctx context.Context, key string) (int, error)

TTLSeconds returns remaining TTL for key, or -1 when no expiry, -2 when missing.

type TenantConfig

type TenantConfig struct {
	PostgRESTURL string `json:"postgrest_url,omitempty"`
	GraphQLURL   string `json:"graphql_url,omitempty"`
	StorageURL   string `json:"storage_url,omitempty"`
	AppMode      string `json:"app_mode,omitempty"`
	AppUpstream  string `json:"app_upstream,omitempty"`
	ViteDevURL   string `json:"vite_dev_url,omitempty"`
	AppStaticDir string `json:"app_static_dir,omitempty"`
	Schema       string `json:"schema,omitempty"`

	DatabaseURL    string `json:"databaseUrl,omitempty"`
	JWTSecret      string `json:"jwtSecret,omitempty"`
	AnonKey        string `json:"anonKey,omitempty"`
	ServiceRoleKey string `json:"serviceRoleKey,omitempty"`

	RealtimeEnabled  *bool  `json:"realtime_enabled,omitempty"`
	RealtimeURL      string `json:"realtime_url,omitempty"`
	FunctionsEnabled *bool  `json:"functions_enabled,omitempty"`

	FunctionsWorkerURL string            `json:"functions_worker_url,omitempty"`
	FunctionWorkerURLs map[string]string `json:"function_worker_urls,omitempty"`

	// Hooks is the model-hook map, table → event → config, as `supatype push` computes it.
	//
	// Cloud has no manifest file on disk, so without this a project's hooks are declared in its schema
	// and never called: the server would find nothing to dispatch and every hooked write would proceed
	// unvalidated, silently. Same shape as the manifest's field so one type describes both paths.
	Hooks map[string]proxy.TableHooks `json:"hooks,omitempty"`

	// CorsAllowedOrigins is merged into the route manifest when present.
	CorsAllowedOrigins []string `json:"cors_allowed_origins,omitempty"`

	StaticCacheHTML         string            `json:"static_cache_html,omitempty"`
	StaticCacheHashedAssets string            `json:"static_cache_hashed_assets,omitempty"`
	StaticCachePrefixes     map[string]string `json:"static_cache_prefixes,omitempty"`

	// RestCacheEnabled gates Valkey-backed REST GET caching on Cloud (false on free tier).
	RestCacheEnabled *bool `json:"rest_cache_enabled,omitempty"`
}

TenantConfig holds routing and configuration for a single tenant, as written by the cloud provisioner and read by supatype-server in managed mode.

func (*TenantConfig) RestCacheOffered

func (tc *TenantConfig) RestCacheOffered() bool

RestCacheOffered returns whether server-side REST caching is offered for this tenant. When unset on a managed pod, defaults to false (fail closed for Cloud cost control).

type TenantManifestCache

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

TenantManifestCache caches merged route manifests per tenant ref for managed mode when SUPATYPE_MANAGED_PROJECT_REF is not set (multi-tenant edge).

func NewTenantManifestCache

func NewTenantManifestCache(vk *Client, ttl time.Duration, base func() *proxy.RouteManifest) *TenantManifestCache

NewTenantManifestCache returns a cache. base must return a fresh clone or immutable manifest used as the file layer for each merge. ttl <= 0 defaults to 30s.

func (*TenantManifestCache) Flush

func (c *TenantManifestCache) Flush()

Flush drops all cached entries (e.g. after local manifest file changes).

func (*TenantManifestCache) Get

Get returns the merged manifest for ref, or base() when ref is empty.

Jump to

Keyboard shortcuts

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