Documentation
¶
Overview ¶
Package backends provides selector store implementations.
Index ¶
- Constants
- func NewStore(ctx context.Context, cfg *config.Config) (selector.Store, error)
- type DynamoDBStore
- func (d *DynamoDBStore) Close() error
- func (d *DynamoDBStore) GetAllStates(ctx context.Context) (map[string]*selector.RateLimitState, error)
- func (d *DynamoDBStore) GetState(ctx context.Context, clientID string) (*selector.RateLimitState, error)
- func (d *DynamoDBStore) SetState(ctx context.Context, clientID string, state *selector.RateLimitState) error
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) GetAllStates(_ context.Context) (map[string]*selector.RateLimitState, error)
- func (m *MemoryStore) GetState(_ context.Context, clientID string) (*selector.RateLimitState, error)
- func (m *MemoryStore) SetState(_ context.Context, clientID string, state *selector.RateLimitState) error
- type RedisStore
- func (r *RedisStore) Close() error
- func (r *RedisStore) GetAllStates(ctx context.Context) (map[string]*selector.RateLimitState, error)
- func (r *RedisStore) GetState(ctx context.Context, clientID string) (*selector.RateLimitState, error)
- func (r *RedisStore) SetState(ctx context.Context, clientID string, state *selector.RateLimitState) error
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 ¶
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
Click to show internal directories.
Click to hide internal directories.