Documentation
¶
Overview ¶
Package redis provides Redis migration helpers for auth stores.
Index ¶
- Constants
- Variables
- func DeleteData(ctx context.Context, client *goredis.Client) error
- func DeleteNamespaceData(ctx context.Context, client *goredis.Client, namespace string) error
- func DrainNamespaceData(ctx context.Context, client *goredis.Client, namespace string, ...) error
- func Migrate(ctx context.Context, client *goredis.Client) error
- func MigrateNamespace(ctx context.Context, client *goredis.Client, namespace string) error
- func Migrations() []migrate.Migration
- func Open(ctx context.Context, options *goredis.Options) (*goredis.Client, error)
- type DrainOptions
- type MigrationDriver
Constants ¶
const (
// DefaultNamespace is the Redis key namespace used by Migrate and DeleteData.
DefaultNamespace = "auth"
)
Variables ¶
var ErrInvalidNamespace = errors.New("redis: invalid namespace")
ErrInvalidNamespace reports a namespace that is unsafe for auth Redis keys.
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 ¶
DeleteData deletes all auth adapter data in DefaultNamespace.
func DeleteNamespaceData ¶
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 MigrateNamespace ¶
MigrateNamespace applies pending Redis migrations in namespace.
func Migrations ¶
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.
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 ¶
func (d *MigrationDriver) Applied(ctx context.Context) (map[int64]migrate.AppliedMigration, error)
Applied returns migrations already applied, keyed by version.
func (*MigrationDriver) EnsureSchema ¶
func (d *MigrationDriver) EnsureSchema(ctx context.Context) error
EnsureSchema verifies the Redis client and namespace.