redis

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package redis provides Redis migration helpers for auth stores.

Index

Constants

View Source
const (
	// DefaultNamespace is the Redis key namespace used by Migrate and DeleteData.
	DefaultNamespace = "auth"
)

Variables

View Source
var ErrInvalidNamespace = errors.New("redis: invalid namespace")

ErrInvalidNamespace reports a namespace that is unsafe for auth Redis keys.

View Source
var ErrNamespaceNotDrained = errors.New("redis: namespace not drained")

ErrNamespaceNotDrained reports that Redis namespace deletion did not observe an empty namespace within the configured pass limit.

Functions

func DeleteData

func DeleteData(ctx context.Context, client *goredis.Client) error

DeleteData deletes all auth adapter data in DefaultNamespace.

func DeleteNamespaceData

func DeleteNamespaceData(ctx context.Context, client *goredis.Client, namespace string) error

DeleteNamespaceData deletes all auth adapter data in namespace.

This is intentionally separate from Migrate so namespace initialization stays non-destructive unless callers explicitly choose to delete data.

This function performs one bounded SCAN pass. If writers may still be adding keys concurrently, use DrainNamespaceData after quiescing writers.

func DrainNamespaceData

func DrainNamespaceData(ctx context.Context, client *goredis.Client, namespace string, options DrainOptions) error

DrainNamespaceData repeatedly deletes auth adapter data in namespace until a configured number of consecutive scan passes observe no matching keys.

This is intended for shutdown/reset workflows where callers can first quiesce writers. MaxPasses prevents unbounded looping if writers continue to create namespace keys during deletion.

func Migrate

func Migrate(ctx context.Context, client *goredis.Client) error

Migrate applies pending Redis migrations using DefaultNamespace.

func MigrateNamespace

func MigrateNamespace(ctx context.Context, client *goredis.Client, namespace string) error

MigrateNamespace applies pending Redis migrations in namespace.

func Migrations

func Migrations() []migrate.Migration

Migrations returns the Redis migrations for the auth adapter.

Redis does not have tables to create. The migration is a no-op schema marker that records the adapter version in the configured namespace.

func Open

func Open(ctx context.Context, options *goredis.Options) (*goredis.Client, error)

Open opens a Redis client and verifies connectivity.

Types

type DrainOptions

type DrainOptions struct {
	// EmptyPasses is the number of consecutive full scan passes that must find
	// no matching keys before deletion is considered complete. Defaults to 2.
	EmptyPasses int

	// MaxPasses is the maximum number of full scan passes before returning
	// ErrNamespaceNotDrained. Defaults to 10.
	MaxPasses int
}

DrainOptions controls repeated Redis namespace deletion passes.

type MigrationDriver

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

MigrationDriver implements migrate.Driver for Redis.

func NewMigrationDriver

func NewMigrationDriver(client *goredis.Client, namespace string) *MigrationDriver

NewMigrationDriver creates a Redis migration driver.

func (*MigrationDriver) Applied

Applied returns migrations already applied, keyed by version.

func (*MigrationDriver) Apply

func (d *MigrationDriver) Apply(ctx context.Context, migration migrate.Migration) error

Apply records a Redis migration as applied.

func (*MigrationDriver) EnsureSchema

func (d *MigrationDriver) EnsureSchema(ctx context.Context) error

EnsureSchema verifies the Redis client and namespace.

Jump to

Keyboard shortcuts

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