redisstore

package
v1.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package redisstore provides a store.KV CSRF token backend built on the native celeris driver/redis client. Tokens are persisted as their UTF-8 bytes under a configurable key prefix (default "csrf:").

The returned store implements store.GetAndDeleter via Redis GETDEL (Redis 6.2+). Callers with older Redis deployments can opt into a non-atomic GET+DEL fallback via [Options.OldRedisCompat].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// KeyPrefix is prepended to every token key. Default: "csrf:".
	KeyPrefix string

	// OldRedisCompat enables a non-atomic GET+DEL fallback for
	// GetAndDelete on Redis versions that do not support GETDEL
	// (< 6.2). When true, single-use token validation is TOCTOU-
	// susceptible under concurrent requests with the same token.
	OldRedisCompat bool
}

Options configure the Redis-backed CSRF store.

type Store

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

Store is a store.KV + store.GetAndDeleter backed by a *redis.Client.

func New

func New(client *redis.Client, opts ...Options) *Store

New returns a new Redis-backed CSRF store.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete implements store.KV.

func (*Store) Get

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

Get implements store.KV.

func (*Store) GetAndDelete

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

GetAndDelete implements store.GetAndDeleter atomically via GETDEL (Redis 6.2+). When [Options.OldRedisCompat] is true, falls back to a non-atomic GET+DEL pair.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set implements store.KV.

Jump to

Keyboard shortcuts

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