raw

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package raw is the explicit trusted Redis command boundary. Normal application features use Foundry's typed cache, data, lease and pub/sub APIs. Commands here require scoped keys and typed decoders, but arbitrary arguments and Lua source are trusted code: Foundry cannot prove that they only refer to declared keys.

Index

Constants

View Source
const (
	MaxArguments     = 256
	MaxCommands      = 256
	MaxRequestBytes  = 16 << 20
	MaxArgumentBytes = 1 << 20
	MaxScriptBytes   = 64 << 10
	MaxReplyBytes    = 16 << 20
	MaxReplyNodes    = 65536
	MaxReplyDepth    = 64
)

Variables

This section is empty.

Functions

func Ignore

func Ignore[R any](p *Pipeline, c Command[R]) error

Ignore still validates the typed decoder and every server/protocol error; it discards only the successful decoded value, never a failed command.

Types

type Argument

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

Argument snapshots one explicit raw value. Zero is invalid; empty Text/Bytes arguments are valid. Use Command.Key for additional keys, not Text(key.String()).

func Bytes

func Bytes(data []byte) Argument

func Int64

func Int64(value int64) Argument

func Text

func Text(text string) Argument

func Uint64

func Uint64(value uint64) Argument

type Backend

type Backend interface {
	ExecuteRaw(context.Context, Request, Limits) (Reply, error)
	ExecuteRawBatch(context.Context, []Request, Mode, Limits) ([]Reply, error)
	ExpireRaw(context.Context, Key, cache.TTL) (bool, error)
}

Backend executes validated immutable requests without automatic retries. Batch errors may follow partial execution; Transaction errors do not roll back earlier successful commands. Capture and bound every reply, including ignored results. ExpireRaw uses one atomic native operation, preserving contents and returning true for an existing key even when Forever is already set. The caller owns the adapter lifecycle. A lost acknowledgement leaves the outcome unknown.

type Builder

type Builder[R any] struct {
	// contains filtered or unexported fields
}

Builder cannot execute until Key produces a Command. Prefix arguments support commands such as XGROUP CREATE whose key is not the first argument.

func NewCommand

func NewCommand[R any](name string, decoder Decoder[R]) Builder[R]

func (Builder[R]) Arg

func (b Builder[R]) Arg(arg Argument) Builder[R]

func (Builder[R]) Key

func (b Builder[R]) Key(key Key) Command[R]

type Command

type Command[R any] struct {
	// contains filtered or unexported fields
}

Command owns immutable arguments and a concrete result decoder. Lua source and raw arguments are trusted; declared key checks are not a sandbox for that code.

func NewScript

func NewScript[R any](source string, key Key, decoder Decoder[R]) Command[R]

NewScript uses a single EVAL with typed KEYS and explicit ARGV, without script cache fallback. It can also be queued in a Pipeline like any other command.

func (Command[R]) Arg

func (c Command[R]) Arg(arg Argument) Command[R]

func (Command[R]) Key

func (c Command[R]) Key(key Key) Command[R]

func (Command[R]) Run

func (c Command[R]) Run(ctx context.Context, s *Store) (R, error)

type Config

type Config struct {
	Namespace                                   keyspace.Namespace
	MaxDeclarations, MaxKeyBytes, MaxConcurrent int
	Timeout                                     time.Duration
	Limits                                      Limits
}

func DefaultConfig

func DefaultConfig(ns keyspace.Namespace) Config

func (Config) Validate

func (c Config) Validate() error

type Declaration

type Declaration[K any] struct {
	// contains filtered or unexported fields
}

func DefineKeys

func DefineKeys[K any](name Name, version Version, codec keyspace.Codec[K]) Declaration[K]

func (Declaration[K]) Bind

func (d Declaration[K]) Bind(s *Store) (Keys[K], error)

type Decoder

type Decoder[R any] struct {
	// contains filtered or unexported fields
}

Decoder preserves the command's concrete result type. Custom callbacks must be deterministic, concurrency-safe and return owned values. Execution owns their lifetime and catches panic/Goexit without abandoning uncooperative callbacks.

func DecodeArray

func DecodeArray[R any](element Decoder[R]) Decoder[[]R]

func DecodeBool

func DecodeBool() Decoder[bool]

func DecodeBytes

func DecodeBytes() Decoder[[]byte]

func DecodeInt64

func DecodeInt64() Decoder[int64]

func DecodeNullable

func DecodeNullable[R any](element Decoder[R]) Decoder[value.Nullable[R]]

func DecodeString

func DecodeString() Decoder[string]

func DecodeUint64

func DecodeUint64() Decoder[uint64]

func DecodeWith

func DecodeWith[R any](fn func(context.Context, Reply) (R, error)) Decoder[R]

type Key

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

Key is an explicit adapter address. Obtain it from Keys.For or FromDataKey. Possessing a key does not statically verify arbitrary command/script arguments.

func FromDataKey

func FromDataKey(key data.Key) (Key, error)

func NewKey

func NewKey(ns keyspace.Namespace, name Name, version Version, logical string) (Key, error)

func (Key) Namespace

func (k Key) Namespace() keyspace.Namespace

func (Key) String

func (k Key) String() string

func (Key) Validate

func (k Key) Validate() error

type Keys

type Keys[K any] struct {
	// contains filtered or unexported fields
}

Keys preserves the domain resource type while resolving explicit raw addresses.

func (Keys[K]) Delete

func (k Keys[K]) Delete(ctx context.Context, input K) (bool, error)

func (Keys[K]) DeleteMany

func (k Keys[K]) DeleteMany(ctx context.Context, inputs ...K) (uint64, error)

DeleteMany encodes all input keys before one atomic DEL and returns a count of distinct existing keys. It never enumerates namespaces or retries an uncertain DEL.

func (Keys[K]) Exists

func (k Keys[K]) Exists(ctx context.Context, input K) (bool, error)

Exists checks a resource of any native Redis data type through its typed key.

func (Keys[K]) Expire

func (k Keys[K]) Expire(ctx context.Context, input K, ttl cache.TTL) (bool, error)

func (Keys[K]) For

func (k Keys[K]) For(ctx context.Context, input K) (Key, error)

func (Keys[K]) Name

func (k Keys[K]) Name() Name

func (Keys[K]) Version

func (k Keys[K]) Version() Version

type Limits

type Limits struct {
	Arguments, Commands, RequestBytes int
	Reply                             ReplyLimits
}

func DefaultLimits

func DefaultLimits() Limits

func (Limits) Validate

func (l Limits) Validate() error

type Mode

type Mode uint8
const (
	Pipelined Mode = iota + 1
	Transaction
)

func (Mode) Validate

func (m Mode) Validate() error

type Name

type Name string

type Pipeline

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

Pipeline is built once and executed once. Queue operations and Run are serialized; whichever obtains the lock first determines inclusion. Execution consumes the pipeline even on failure. Construct another pipeline for a deliberate new attempt.

func NewPipeline

func NewPipeline(mode Mode) (*Pipeline, error)

func (*Pipeline) IsEmpty

func (p *Pipeline) IsEmpty() bool

func (*Pipeline) Len

func (p *Pipeline) Len() int

Len reports queued commands. Run claims and clears that queue before I/O.

func (*Pipeline) Mode

func (p *Pipeline) Mode() Mode

func (*Pipeline) Run

func (p *Pipeline) Run(ctx context.Context, s *Store) error

type Reply

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

Reply is an immutable, owned RESP2 value for explicit decoders and adapters. Its zero value is Redis nil. Array returns a new slice of immutable child values.

func CaptureReplies

func CaptureReplies(ctx context.Context, input []any, l ReplyLimits) ([]Reply, error)

CaptureReplies shares one budget across a complete pipeline, including its synthetic array root. Errors return no partial batch and do not expose payloads.

func CaptureReply

func CaptureReply(ctx context.Context, input any, l ReplyLimits) (Reply, error)

CaptureReply is the adapter boundary for driver-decoded RESP2 (nil, int64, string, or []any). No driver types escape. Bounds apply after RESP parsing.

func (Reply) Array

func (r Reply) Array() ([]Reply, error)

func (Reply) Integer

func (r Reply) Integer() (int64, error)

func (Reply) IsNull

func (r Reply) IsNull() bool

func (Reply) Text

func (r Reply) Text() (string, error)

type ReplyLimits

type ReplyLimits struct{ Bytes, Nodes, Depth int }

ReplyLimits apply to the complete reply, or the combined batch. They bound retained/captured replies after the driver parses RESP, not malicious server parser allocations. Depth counts the root as zero.

func DefaultReplyLimits

func DefaultReplyLimits() ReplyLimits

func (ReplyLimits) Validate

func (l ReplyLimits) Validate() error

type Request

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

Request is an immutable adapter invocation. Only a command containing a typed key, or a script constructor requiring a key, can produce one.

func (Request) Arguments

func (r Request) Arguments() []string

Arguments returns owned command arguments (including its name) or script ARGV.

func (Request) Bytes

func (r Request) Bytes() int

func (Request) IsScript

func (r Request) IsScript() bool

func (Request) Keys

func (r Request) Keys() []Key

func (Request) Source

func (r Request) Source() string

func (Request) Validate

func (r Request) Validate(ns keyspace.Namespace, l Limits) error

type Result

type Result[R any] struct {
	// contains filtered or unexported fields
}

Result is a typed pipeline receipt. Value is available only after the entire execution and all decoders succeed. Repeated Value calls share the application's decoded value; callers own synchronization of any maps/slices it contains.

func Queue

func Queue[R any](p *Pipeline, c Command[R]) (Result[R], error)

func (Result[R]) Value

func (r Result[R]) Value() (R, error)

type Store

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

func NewStore

func NewStore(backend Backend, c Config) (*Store, error)

func (*Store) Namespace

func (s *Store) Namespace() keyspace.Namespace

type Version

type Version uint32

Jump to

Keyboard shortcuts

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