variables

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ValkeyWrongTypeOrNotFoundError is returned by custom Valkey module commands
	// when the key is missing or has an incompatible type.
	ValkeyWrongTypeOrNotFoundError = "WRONGTYPE_OR_NOTFOUND"
	// PriorityListGetOrCreateCommand fetches or initializes a module-backed priority list.
	PriorityListGetOrCreateCommand = "PRIORITYLIST.GETORCREATE"
	// PriorityListGetCommand fetches a module-backed priority list.
	PriorityListGetCommand = "PRIORITYLIST.GET"
	// HashSetGetOrCreateCommand fetches or initializes a module-backed hash set value.
	HashSetGetOrCreateCommand = "HASHSET.GETORCREATE"
	// HashSetLookupCommand fetches a module-backed hash set value.
	HashSetLookupCommand = "HASHSET.LOOKUP"
)

Variables

View Source
var ErrInvalidDefault = errors.New("invalid default")

ErrInvalidDefault is the sentinel for any canonicalization failure.

View Source
var ErrUnsupportedDataType = errors.New("unsupported dataType")

ErrUnsupportedDataType is returned by Resolve and Typed when given a DataType not in the canonical enum.

Functions

func CanonicalizeMap added in v0.4.1

func CanonicalizeMap(raw json.RawMessage) (map[string]string, error)

CanonicalizeMap decodes raw as map[string]string. Null values and non-string values are rejected.

func CanonicalizeScalar added in v0.4.1

func CanonicalizeScalar(raw json.RawMessage, dataType DataType) (string, error)

CanonicalizeScalar returns the canonical Valkey string form of raw as dataType. Non-scalar dataType returns an error.

func CanonicalizeSet added in v0.4.1

func CanonicalizeSet(raw json.RawMessage) ([]string, error)

CanonicalizeSet decodes raw as []string. Null elements and non-string elements are rejected.

Types

type DataType added in v0.4.1

type DataType string

DataType is the canonical set of variable data types recognized across MDAI components (operator CRD, gateway, event-hub, data-core). The literal string values match the kubebuilder enum on MdaiHub's VariableDataType field and are the wire format used in event payloads and audit entries.

const (
	DataTypeInt     DataType = "int"     // signed integer, stored as a string in Valkey
	DataTypeFloat   DataType = "float"   // 64-bit float, stored as a string in Valkey; writers must canonicalize via strconv.FormatFloat(v, 'g', -1, 64)
	DataTypeBoolean DataType = "boolean" // "true" or "false" as a string in Valkey
	DataTypeString  DataType = "string"
	DataTypeSet     DataType = "set" // Valkey SET
	DataTypeMap     DataType = "map" // Valkey HASH; field-value pairs are strings

	DataTypeMetaHashSet      DataType = "metaHashSet"      // module-backed lookup table (input key → value via a referenced set)
	DataTypeMetaPriorityList DataType = "metaPriorityList" // module-backed ordered references; evaluates to the first non-empty
)

type OperationArgs

type OperationArgs struct {
	MapKey   string
	HubName  string
	Value    string
	IntValue int64
	MapValue map[string]string
}

type Reader added in v0.4.1

type Reader interface {
	GetString(ctx context.Context, variableKey, hubName string) (string, bool, error)
	GetSetAsStringSlice(ctx context.Context, variableKey, hubName string) ([]string, error)
	GetMap(ctx context.Context, variableKey, hubName string) (map[string]string, error)
	GetMetaPriorityList(ctx context.Context, variableKey, hubName string) ([]string, bool, error)
	GetMetaHashSet(ctx context.Context, variableKey, hubName string) (string, bool, error)
}

Reader is the read interface Resolve depends on; ValkeyAdapter satisfies it.

type ResolveResult added in v0.4.1

type ResolveResult struct {
	Value     any
	Found     bool
	IsDefault bool
	DataType  DataType
}

ResolveResult is the outcome of a variable read. Value is the canonical form (string for scalars, []string for sets, map[string]string for maps). IsDefault distinguishes a materialized default from a stored value.

func Resolve added in v0.4.1

func Resolve(
	ctx context.Context,
	adapter Reader,
	hubName, varKey string,
	dataType DataType,
	defaultRaw json.RawMessage,
) (ResolveResult, error)

Resolve reads the variable; on not-found it materializes defaultRaw via the canonicalizers. defaultRaw==nil means no default declared. For set/map, a zero-length read is treated as not-found.

func (ResolveResult) Typed added in v0.4.1

func (r ResolveResult) Typed() (any, error)

Typed returns Value as int64, float64, bool, string, []string, or map[string]string per the originating dataType.

type ValkeyAdapter

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

func NewValkeyAdapter

func NewValkeyAdapter(client valkey.Client, logger *zap.Logger, opts ...ValkeyAdapterOption) *ValkeyAdapter

func (*ValkeyAdapter) AddElementToSet

func (r *ValkeyAdapter) AddElementToSet(variableKey string, hubName string, value string) valkey.Completed

func (*ValkeyAdapter) AuditStreamExpiry

func (r *ValkeyAdapter) AuditStreamExpiry() time.Duration

func (*ValkeyAdapter) BulkSetMap

func (r *ValkeyAdapter) BulkSetMap(variableKey string, hubName string, values map[string]string) valkey.Completed

func (*ValkeyAdapter) DeleteKeysWithPrefixUsingScan

func (r *ValkeyAdapter) DeleteKeysWithPrefixUsingScan(ctx context.Context, keep map[string]struct{}, hubName string) error

func (*ValkeyAdapter) DeleteString

func (r *ValkeyAdapter) DeleteString(variableKey string, hubName string) valkey.Completed

func (*ValkeyAdapter) Exists added in v0.3.1

func (r *ValkeyAdapter) Exists(ctx context.Context, variableKey string, hubName string) (bool, error)

func (*ValkeyAdapter) GetMap

func (r *ValkeyAdapter) GetMap(ctx context.Context, variableKey string, hubName string) (map[string]string, error)

func (*ValkeyAdapter) GetMapAsString

func (r *ValkeyAdapter) GetMapAsString(ctx context.Context, variableKey string, hubName string) (string, error)

func (*ValkeyAdapter) GetMetaHashSet added in v0.3.1

func (r *ValkeyAdapter) GetMetaHashSet(ctx context.Context, variableKey string, hubName string) (string, bool, error)

func (*ValkeyAdapter) GetMetaPriorityList added in v0.3.1

func (r *ValkeyAdapter) GetMetaPriorityList(ctx context.Context, variableKey string, hubName string) ([]string, bool, error)

func (*ValkeyAdapter) GetOrCreateMetaHashSet

func (r *ValkeyAdapter) GetOrCreateMetaHashSet(ctx context.Context, variableKey string, hubName string, variableStringKey string, variableSetKey string) (string, bool, error)

func (*ValkeyAdapter) GetOrCreateMetaPriorityList

func (r *ValkeyAdapter) GetOrCreateMetaPriorityList(ctx context.Context, variableKey string, hubName string, variableRefs []string) ([]string, bool, error)

func (*ValkeyAdapter) GetSetAsStringSlice

func (r *ValkeyAdapter) GetSetAsStringSlice(ctx context.Context, variableKey string, hubName string) ([]string, error)

func (*ValkeyAdapter) GetString

func (r *ValkeyAdapter) GetString(ctx context.Context, variableKey string, hubName string) (string, bool, error)

GetString retrieves the string, int and boolean variable. It returns the value, a boolean indicating whether the key was found, and any error encountered.

func (*ValkeyAdapter) IntDecrBy

func (r *ValkeyAdapter) IntDecrBy(variableKey string, hubName string, value int64) valkey.Completed

func (*ValkeyAdapter) IntIncrBy

func (r *ValkeyAdapter) IntIncrBy(variableKey string, hubName string, value int64) valkey.Completed

func (*ValkeyAdapter) RemoveElementFromSet

func (r *ValkeyAdapter) RemoveElementFromSet(variableKey string, hubName string, value string) valkey.Completed

func (*ValkeyAdapter) RemoveMapEntry

func (r *ValkeyAdapter) RemoveMapEntry(variableKey string, hubName string, field string) valkey.Completed

func (*ValkeyAdapter) SetMapEntry

func (r *ValkeyAdapter) SetMapEntry(variableKey string, hubName string, field string, value string) valkey.Completed

func (*ValkeyAdapter) SetString

func (r *ValkeyAdapter) SetString(variableKey string, hubName string, value string) valkey.Completed

type ValkeyAdapterOption

type ValkeyAdapterOption func(*ValkeyAdapter)

func WithValkeyAuditStreamExpiry

func WithValkeyAuditStreamExpiry(expiry time.Duration) ValkeyAdapterOption

Jump to

Keyboard shortcuts

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