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

gcpredis

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 43 Imported by: 0

README

Memorystore for Redis

Parity grade: B · SDK cloud.google.com/go/redis@v1.26.0 · last audited 2026-10-21 (c7e82dfd3)

Coverage

Metric Value
PARITY entries audited 14 (13 ok, 1 partial)
Feature families 4 (2 ok, 2 partial)
Known gaps 7
Deferred items 0
Resource leaks clean
Known gaps
  • redis_configs are validated against the supported key set and Redis version and reported back, but miniredis has no CONFIG command so they never change engine behaviour (eviction, keyspace notifications, defrag).
  • memory_size_gb is not enforced as a maxmemory limit.
  • Import supports RDB files that use plain encodings (strings, lists, sets, sorted sets, hashes, LZF and integer strings); files written by a real Redis server with ziplist, listpack, intset or stream encodings fail with INVALID_ARGUMENT. Export fails on instances holding streams and drops hash field TTLs.
  • STANDARD_HA and read replicas are metadata only: one server serves both the primary and read endpoint (read_endpoint equals host), and failover swaps zone labels.
  • RDB persistence_config is recorded but no periodic snapshots are taken (the emulator's own snapshot persistence covers restarts).
  • After a restore every instance starts on a new port and, for TLS, a new CA.
  • Cross-region replication, customer-managed keys, maintenance_version and suspension reasons are stored or empty but not modelled.

More

Documentation

Index

Constants

View Source
const DefaultPort = 8133

DefaultPort is the dedicated gRPC listener's default TCP port.

Variables

View Source
var ErrNilAppContext = errors.New("gcpredis: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

Functions

func GetLocation

func GetLocation(req *location.GetLocationRequest) (*location.Location, error)

GetLocation returns one supported location.

func ListLocations

func ListLocations(req *location.ListLocationsRequest) ([]*location.Location, string, error)

ListLocations lists the supported locations of a project.

Types

type ConfigProvider

type ConfigProvider interface {
	GetGCPRedisSettings() Settings
}

ConfigProvider extracts Memorystore for Redis configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Memorystore for Redis API (v1) on a dedicated gRPC listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) API

func (h *Handler) API() redispb.CloudRedisServer

API exposes the CloudRedis server for in-process callers (dashboard proxy).

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

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 supported gRPC methods.

func (*Handler) Handler

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

Handler returns a 404 handler; the real API is gRPC on the dedicated port.

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 clears all in-memory state.

func (*Handler) Restore

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

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

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

RouteMatcher never matches: Memorystore for Redis runs on its own gRPC listener.

func (*Handler) Shutdown

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

Shutdown stops the gRPC server and every instance's Redis server, forcing a close after a short grace period.

func (*Handler) Snapshot

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

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

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

InMemoryBackend holds all Memorystore for Redis state under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend that serves instances on ephemeral loopback ports.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops every instance's Redis server and waits for background work.

func (*InMemoryBackend) CreateInstance

CreateInstance starts creating an instance; the returned operation completes once its Redis server is up.

func (*InMemoryBackend) DeleteInstance

func (b *InMemoryBackend) DeleteInstance(name string) (*longrunningpb.Operation, error)

DeleteInstance deletes an instance and stops its Redis server.

func (*InMemoryBackend) ExportInstance

ExportInstance writes an instance's data to Cloud Storage as an RDB file.

func (*InMemoryBackend) FailoverInstance

FailoverInstance swaps the primary and replica zones of a STANDARD_HA instance.

func (*InMemoryBackend) GetInstance

func (b *InMemoryBackend) GetInstance(name string) (*redispb.Instance, error)

GetInstance returns an instance.

func (*InMemoryBackend) GetInstanceAuthString

func (b *InMemoryBackend) GetInstanceAuthString(name string) (*redispb.InstanceAuthString, error)

GetInstanceAuthString returns the AUTH string of an instance with AUTH enabled.

func (*InMemoryBackend) ImportInstance

ImportInstance replaces an instance's data with an RDB file read from Cloud Storage.

func (*InMemoryBackend) ListInstances

ListInstances lists instances under a location, or every location with "-".

func (*InMemoryBackend) RescheduleMaintenance

RescheduleMaintenance sets when the next maintenance runs.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset stops every instance and clears all state.

func (*InMemoryBackend) Restore

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

Restore loads a snapshot. Instances caught mid-creation or mid-deletion are dropped, other transient states settle to READY, and every Redis server starts again on a fresh port.

func (*InMemoryBackend) SetObjectStore

func (b *InMemoryBackend) SetObjectStore(o ObjectStore)

SetObjectStore connects ImportInstance and ExportInstance to an object store.

func (*InMemoryBackend) SetPortPool

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

SetPortPool makes instances take their Redis ports from alloc.

func (*InMemoryBackend) Snapshot

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

Snapshot serialises every instance with its keyspace; Redis servers and TLS CAs are rebuilt on restore.

func (*InMemoryBackend) UpdateInstance

UpdateInstance applies the masked fields of the request's instance.

func (*InMemoryBackend) UpgradeInstance

UpgradeInstance moves an instance to a newer Redis version.

type ObjectStore

type ObjectStore interface {
	ReadObject(bucket, object string) ([]byte, error)
	WriteObject(bucket, object string, data []byte) error
}

ObjectStore reads and writes objects in the GCS emulator, for ImportInstance and ExportInstance.

type Provider

type Provider struct{}

Provider implements service.Provider for Google Memorystore for Redis. It serves gRPC on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 179-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPRedis.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

Jump to

Keyboard shortcuts

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