Help us shape the future of Go! Take the 2026 Go Developer Survey

generation

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package generation is what `brevis-sql build` writes when a model is rebuilt, and what `brevis-sql-api` reads to know its cached answers are stale -- through a Redis client of its own, written against RESP2.

A CLIENT IN THIS FILE AND NOT A LIBRARY, for the reason the BigQuery REST endpoint is two hundred lines in this module rather than the official client: `brevis-sql` runs as a step in every pipeline that builds a model, its weight is guarded by `sql-weight.sh`, and what it asks of Redis is SET. What the API asks is GET, MGET and SET with an expiry. Five commands, one protocol, specified and short; the cost is this file and its fuzz test.

WHAT IT DOES NOT DO: Sentinel, Cluster redirection, pipelining, pub/sub. Cluster works only because every key this module writes carries the `{brevis}` hash tag, which puts an MGET's keys on one slot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(model string) string

Key is where a model's generation lives.

func Model

func Model(dialect, ref string) string

Model is a relation's name as a generation is keyed: the same for the build that writes it, the step that bumps it and the API that reads it.

FOUND IN THE SHIP REVIEW: those three named a model three ways and nothing made them agree, so a generation was written under one name and read under another, and an answer stayed until its ttl. Postgres folds an unquoted identifier to lower case, so the name is lowered there; BigQuery names are case-sensitive and may lead with the project, which is dropped -- a build writes `schema.name` whatever project it ran in.

func NewToken

func NewToken() string

NewToken is a fresh generation: when it was written, and sixteen random hex digits.

NOT A RUN ID, because a step is given none -- the engine hands a step its parameters and nothing that names the run. What a generation has to be is DIFFERENT after every rebuild, and this is; the time in front is for the human reading Redis, not for any comparison.

func Read

func Read(ctx context.Context, c *Client, models []string) ([]string, error)

Read is each model's generation, in the order asked, in one round trip. A model with none is "": built by something that does not write one, or never built -- either way a stable part of a cache key.

func Write

func Write(ctx context.Context, c *Client, models []string, token string) error

Write records that each model was rebuilt, as one generation.

NO EXPIRY. A generation stays until the next build replaces it; one that expired would turn every cached answer over that model into a miss on a timer nobody set, which is the clock this whole design exists to avoid.

Types

type Client

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

Client is a small pool of connections to one Redis.

func Open

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

Open reads an address -- `host:port`, `redis://[user:password@]host:port[/db]` or `rediss://` for TLS -- and connects to nothing yet.

AN ERROR NEVER QUOTES THE ADDRESS, which may carry a password.

func (*Client) Close

func (c *Client) Close() error

Close drops every idle connection.

func (*Client) Get

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

Get reads one value, and whether there was one.

func (*Client) MGet

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

MGet reads several values in one round trip; an absent one is nil.

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value. A zero ttl is no expiry, which is what a generation is: it stays until the next build replaces it.

Jump to

Keyboard shortcuts

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