backends

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package backends provides selector store implementations.

Index

Constants

View Source
const (
	// DefaultTableName is the default DynamoDB table name when not configured.
	DefaultTableName = "rate_limits"
	// DefaultTTLMinutes is the default TTL in minutes for DynamoDB rate limit items.
	DefaultTTLMinutes = 120
)

Variables

This section is empty.

Functions

func NewStore

func NewStore(ctx context.Context, cfg *config.Config) (selector.Store, error)

NewStore creates a selector.Store from the application config.

Types

type DynamoDBStore

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

DynamoDBStore is a DynamoDB-backed implementation of selector.Store.

func NewDynamoDBStore

func NewDynamoDBStore(client db.DynamoDBAPI, table string, ttlMinutes int) *DynamoDBStore

NewDynamoDBStore returns a new DynamoDB store.

func (*DynamoDBStore) Close

func (d *DynamoDBStore) Close() error

func (*DynamoDBStore) GetAllStates

func (d *DynamoDBStore) GetAllStates(ctx context.Context) (map[string]*selector.RateLimitState, error)

func (*DynamoDBStore) GetState

func (d *DynamoDBStore) GetState(ctx context.Context, clientID string) (*selector.RateLimitState, error)

func (*DynamoDBStore) SetState

func (d *DynamoDBStore) SetState(ctx context.Context, clientID string, state *selector.RateLimitState) error

type MemoryStore

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

MemoryStore is an in-memory implementation of selector.Store.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns a new in-memory store.

func (*MemoryStore) Close

func (m *MemoryStore) Close() error

func (*MemoryStore) GetAllStates

func (m *MemoryStore) GetAllStates(_ context.Context) (map[string]*selector.RateLimitState, error)

func (*MemoryStore) GetState

func (m *MemoryStore) GetState(_ context.Context, clientID string) (*selector.RateLimitState, error)

func (*MemoryStore) SetState

func (m *MemoryStore) SetState(_ context.Context, clientID string, state *selector.RateLimitState) error

type RedisStore

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

RedisStore is a Redis-backed implementation of selector.Store.

State is stored as Redis Hashes for efficient field access:

gate:ratelimit:{client_id} -> Hash{remaining, reset_at, last_updated}

SetState uses a Lua script for atomic compare-and-swap to prevent stale writes from overwriting fresher state in multi-instance deployments. Keys automatically expire based on rate limit reset time plus a buffer.

func NewRedisStore

func NewRedisStore(client redis.Cmdable) *RedisStore

NewRedisStore returns a new Redis store.

func (*RedisStore) Close

func (r *RedisStore) Close() error

func (*RedisStore) GetAllStates

func (r *RedisStore) GetAllStates(ctx context.Context) (map[string]*selector.RateLimitState, error)

func (*RedisStore) GetState

func (r *RedisStore) GetState(ctx context.Context, clientID string) (*selector.RateLimitState, error)

func (*RedisStore) SetState

func (r *RedisStore) SetState(ctx context.Context, clientID string, state *selector.RateLimitState) error

Jump to

Keyboard shortcuts

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