redisflags

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package redisflags provides a Redis-backed feature flag store for the core/featureflag evaluator. Complements the existing in-memory and SQL stores.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("redisflags: key not found")

ErrNotFound is returned by a RedisClient implementation when the key is not present. Distinguishing this from connection/protocol errors matters: a real error must not be silently treated as "flag absent".

Functions

This section is empty.

Types

type Config

type Config struct {
	// KeyPrefix is prepended to all Redis keys. Default: "flag:".
	KeyPrefix string
}

Config configures the Redis flag store.

type Flag

type Flag struct {
	Key         string    `json:"key"`
	Enabled     bool      `json:"enabled"`
	RolloutPct  int       `json:"rolloutPercent,omitempty"` // 0-100
	Description string    `json:"description,omitempty"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

Flag represents a feature flag stored in Redis.

type RedisClient

type RedisClient interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string, ttl time.Duration) error
	Del(ctx context.Context, keys ...string) error
	Scan(ctx context.Context, cursor uint64, pattern string, count int64) (uint64, []string, error)
	MGet(ctx context.Context, keys ...string) ([]string, error)
}

RedisClient is the minimal Redis interface needed.

Scan + MGet exist so List can paginate over keys without blocking the server with KEYS. The interface is intentionally narrow; an adapter for go-redis is straightforward.

type Store

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

Store implements featureflag.Store backed by Redis.

func New

func New(client RedisClient, cfg Config) *Store

New creates a new Redis-backed feature flag store.

func (*Store) Delete

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

Delete removes a flag.

func (*Store) Get

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

Get retrieves a flag by key. Returns (nil, nil) if not found. All other transport errors are surfaced to the caller.

func (*Store) IsEnabled

func (s *Store) IsEnabled(ctx context.Context, key string) bool

IsEnabled checks if a flag is enabled. Returns false if not found or on transport errors (caller can use Get to distinguish).

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Flag, error)

List returns all flags. Uses Scan to iterate keys and MGet to batch- fetch values; never blocks Redis with KEYS.

func (*Store) Set

func (s *Store) Set(ctx context.Context, flag *Flag) error

Set saves a flag. Validates RolloutPct ∈ [0, 100].

Jump to

Keyboard shortcuts

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