azureredis

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 30 Imported by: ? 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.

README

Azure Cache for Redis

Parity grade: B · SDK azure-sdk-for-go/sdk/resourcemanager/redis/armredis/v3@v3.3.0 · last audited 2026-10-22 (364908f83)

Coverage

Metric Value
PARITY entries audited 13 (10 ok, 3 partial)
Feature families 3 (3 ok)
Known gaps 9
Deferred items 0
Resource leaks clean
Known gaps
  • Microsoft.Cache/redisEnterprise (Redis Enterprise and Azure Managed Redis) is not implemented: the resource provider would live in services/azurearm (rp_redis*.go handle only Microsoft.Cache/redis), which this work may not edit.
  • Clustering (shardCount, replicasPerPrimary), VNet injection, private endpoints, zones allocation and geo-replication data flow are not modelled; a cache is one Redis server.
  • redisConfiguration is stored and echoed; miniredis has no CONFIG, so maxmemory-policy, maxclients and notify-keyspace-events are not enforced. rdb/aof backup settings only decide whether a full reboot keeps data.
  • Import accepts one RDB file; compact ziplist/listpack/intset encodings and streams fail with a 400.
  • Create completes the server immediately; only the reported provisioningState lags.
  • Microsoft.Cache/redisEnterprise (Redis Enterprise and Azure Managed Redis) is not implemented: the resource provider would live in services/azurearm (rp_redis*.go handle only Microsoft.Cache/redis), which this work may not edit.
  • Clustering, VNet injection, private endpoints and geo-replication data flow are not modelled.
  • redisConfiguration settings are stored but not enforced: they stay in services/azurearm (rp_redis_cache.go:91, rp_redis_body.go:115) and never reach this service's Spec, and miniredis has no CONFIG, eviction or keyspace notifications to apply them to.
  • Entra authentication: tokens are not re-checked for expiry on an open connection; the built-in access policy permission strings are not published by Learn or the REST reference and are derived from the policy names; deleting a custom policy that an assignment uses is refused although the REST page documents no such rule.

More

Documentation

Index

Constants

View Source
const (
	MaxDatabases = 16
	MaxScan      = 500
	MaxElements  = 100
	MaxValueLen  = 4096
)

Inspection limits.

View Source
const (
	RebootPrimary   = "PrimaryNode"
	RebootSecondary = "SecondaryNode"
	RebootAll       = "AllNodes"
)

Reboot types accepted by Reboot.

View Source
const (
	KeyPrimary   = "Primary"
	KeySecondary = "Secondary"
)

Access key names accepted by RegenerateKey.

View Source
const (
	SKUBasic    = "Basic"
	SKUStandard = "Standard"
	SKUPremium  = "Premium"
)

SKU names.

Variables

View Source
var (
	// ErrNotFound is returned for an unknown cache.
	ErrNotFound = errors.New("azureredis: cache not found")
	// ErrInvalid is returned for a malformed request.
	ErrInvalid = errors.New("azureredis: invalid request")
	// ErrNoBlobStore is returned when import or export has no Blob Storage to talk to.
	ErrNoBlobStore = errors.New("azureredis: blob storage is not available")
	// ErrNilAppContext is returned when Init is called with a nil AppContext.
	ErrNilAppContext = errors.New("azureredis: nil app context")
)

Functions

This section is empty.

Types

type AccessAssignment

type AccessAssignment struct {
	ObjectID    string `json:"objectId"`
	Alias       string `json:"alias"`
	Permissions string `json:"permissions"`
}

AccessAssignment grants a principal the permissions of a data access policy; Alias is also the user name accepted for token authentication.

type BlobStore

type BlobStore interface {
	ReadBlob(container, blob string) ([]byte, error)
	WriteBlob(container, blob string, data []byte) error
}

BlobStore reads and writes blobs in the Blob Storage emulator, for ImportData and ExportData.

type CacheInfo

type CacheInfo struct {
	ID       string
	Spec     Spec
	Endpoint Endpoint
	Keys     int
}

CacheInfo describes one running cache.

type ConfigProvider

type ConfigProvider interface {
	GetAzureRedisSettings() Settings
}

ConfigProvider extracts the Azure Cache for Redis settings from the AppContext config.

type Endpoint

type Endpoint struct {
	Host    string
	Port    int
	SSLPort int
}

Endpoint is where a cache's servers listen. Port is 0 while the non-TLS port is disabled.

type Handler

type Handler struct {
	Backend *InMemoryBackend
}

Handler owns the cache servers. Azure Cache for Redis has no HTTP data plane: ARM manages caches and clients speak Redis to each cache's own ports, so the handler never matches a request.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler wraps backend.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the operations ARM's Microsoft.Cache provider drives.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset stops every cache.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches.

func (*Handler) Shutdown

func (h *Handler) Shutdown(context.Context)

Shutdown stops every cache.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable.

type IPRange

type IPRange struct {
	Start string `json:"start"`
	End   string `json:"end"`
}

IPRange is one firewall rule: a contiguous, inclusive IPv4 range.

type InMemoryBackend

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

InMemoryBackend runs one embedded Redis server per cache, with a TLS port always on and a plaintext port only while the cache enables it.

func NewInMemoryBackend

func NewInMemoryBackend(cfg Settings) *InMemoryBackend

NewInMemoryBackend creates an empty backend on ephemeral loopback ports.

func (*InMemoryBackend) Caches

func (b *InMemoryBackend) Caches() []CacheInfo

Caches lists the running caches by ID.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops every cache.

func (*InMemoryBackend) Delete

func (b *InMemoryBackend) Delete(key string) error

Delete stops the cache's servers and discards its data.

func (*InMemoryBackend) Endpoint

func (b *InMemoryBackend) Endpoint(key string) (Endpoint, bool)

Endpoint reports where the cache listens.

func (*InMemoryBackend) Ensure

func (b *InMemoryBackend) Ensure(key string, spec Spec) (Endpoint, error)

Ensure creates the cache, or applies spec to an existing one, and returns where it listens.

func (*InMemoryBackend) Export

func (b *InMemoryBackend) Export(key, format, prefix, containerURL string) error

Export writes the cache's data to <prefix>.rdb in the container named by containerURL.

func (*InMemoryBackend) Import

func (b *InMemoryBackend) Import(key, format string, files []string) error

Import replaces the cache's data with the RDB file at the blob URL.

func (*InMemoryBackend) Keys

func (b *InMemoryBackend) Keys(key string) (Keys, error)

Keys returns the cache's access keys.

func (*InMemoryBackend) Reboot

func (b *InMemoryBackend) Reboot(key, rebootType string) error

Reboot restarts the selected nodes. Data is flushed when no surviving node holds it; client connections drop unless only a replica reboots.

func (*InMemoryBackend) RegenerateKey

func (b *InMemoryBackend) RegenerateKey(key, keyType string) (Keys, error)

RegenerateKey replaces one access key; the old value stops authenticating.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset stops every cache.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot, starting every cache again on fresh ports.

func (*InMemoryBackend) Scan

func (b *InMemoryBackend) Scan(key string, db int, pattern, after string, limit int) ([]KeyEntry, string, error)

Scan lists up to limit keys of database db that match the glob pattern (* and ? only), in key order, starting after the cursor key. The returned next is empty once the scan is complete.

func (*InMemoryBackend) SetBlobStore

func (b *InMemoryBackend) SetBlobStore(s BlobStore)

SetBlobStore connects ImportData and ExportData to Blob Storage.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the clock that decides when a Microsoft Entra token has expired.

func (*InMemoryBackend) SetPortPool

func (b *InMemoryBackend) SetPortPool(alloc *portalloc.Allocator)

SetPortPool makes caches take their Redis ports from alloc.

func (*InMemoryBackend) SetTokenValidator

func (b *InMemoryBackend) SetTokenValidator(v TokenValidator)

SetTokenValidator lets caches with Entra authentication enabled accept Microsoft Entra tokens.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises every cache with its keys and keyspace; servers and ports are rebuilt on restore.

func (*InMemoryBackend) Value

func (b *InMemoryBackend) Value(key string, db int, name string) (KeyValue, error)

Value returns a capped view of the key's value without altering it.

type KeyEntry

type KeyEntry struct {
	Key  string
	Type string
	TTL  time.Duration
}

KeyEntry is one key found by Scan.

type KeyValue

type KeyValue struct {
	Key       string
	Type      string
	Text      string
	Elements  []string
	Total     int
	TTL       time.Duration
	Truncated bool
}

KeyValue is a capped view of one key's value.

type Keys

type Keys struct {
	Primary   string
	Secondary string
}

Keys are a cache's two access keys; either authenticates.

type Provider

type Provider struct{}

Provider implements service.Provider for Azure Cache for Redis.

func (*Provider) Init

Init builds the backend and handler.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	TLSCertFile string `` //nolint:lll // config struct tags are intentionally verbose
	/* 215-byte string literal not displayed */
	TLSKeyFile string `json:"tlsKeyFile"  env:"AZURE_REDIS_TLS_KEY"  name:"tls-key"  help:"Path to the PEM key matching --azure-redis-tls-cert."` //nolint:lll // config struct tags are intentionally verbose
}

Settings is the Kong-embedded configuration of the Azure Cache for Redis emulator.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider exists.

type Spec

type Spec struct {
	SKU               string             `json:"sku"`
	MinTLS            string             `json:"minTls"`
	Firewall          []IPRange          `json:"firewall,omitempty"`
	Assignments       []AccessAssignment `json:"accessAssignments,omitempty"`
	EnableNonSSLPort  bool               `json:"enableNonSslPort"`
	Persistence       bool               `json:"persistence"`
	AuthNotRequired   bool               `json:"authNotRequired,omitempty"`
	DisableAccessKeys bool               `json:"disableAccessKeys,omitempty"`
	EntraEnabled      bool               `json:"entraEnabled,omitempty"`
}

Spec is the part of a cache's ARM configuration the Redis servers act on.

type TokenValidator

type TokenValidator func(token string) (objectID string, ok bool)

TokenValidator checks a Microsoft Entra access token for the Redis audience and returns its principal's object ID.

Jump to

Keyboard shortcuts

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