redis

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

authstate/redis

This package adapts a pinned go-redis client to authstate.Store[T] for Redis and Valkey. It uses SET NX with expiry and GETDEL; it is not a general Redis client. Connect to a loopback or same-Pod proxy when upstream TLS is required. The caller owns and closes the supplied client.

client := goredis.NewUniversalClient(&goredis.UniversalOptions{
	Addrs: []string{"127.0.0.1:6379"},
	Protocol: 2,
})
store, err := redisstore.NewStore[oauth.Transaction](
	client,
	oauth.TransactionCodec{},
	redisstore.Options{Prefix: "petitweb:", Namespace: "oauth"},
)

Prefix and Namespace are required. Direct Redis Cluster redirection is not supported through a single TCP TLS tunnel; use a stable proxy endpoint.

Documentation

Overview

Package redis provides a Redis and Valkey backed authstate.Store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Prefix        string
	Namespace     string
	Now           func() time.Time
	MaxKeyBytes   int
	MaxValueBytes int
}

Options controls key isolation, resource bounds, and expiry behavior.

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

Store persists expiring, single-use authentication state in Redis or Valkey.

func NewStore

func NewStore[T any](client goredis.UniversalClient, codec authstate.Codec[T], options Options) (*Store[T], error)

NewStore constructs a Redis or Valkey backed Store. The caller retains ownership of client and is responsible for closing it.

func (*Store[T]) Put

func (s *Store[T]) Put(ctx context.Context, key string, value T, expiresAt time.Time) error

func (*Store[T]) Take

func (s *Store[T]) Take(ctx context.Context, key string) (T, error)

Jump to

Keyboard shortcuts

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