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 ¶
- Variables
- type Config
- type Flag
- type RedisClient
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) (*Flag, error)
- func (s *Store) IsEnabled(ctx context.Context, key string) bool
- func (s *Store) List(ctx context.Context) ([]*Flag, error)
- func (s *Store) Set(ctx context.Context, flag *Flag) error
Constants ¶
This section is empty.
Variables ¶
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) Get ¶
Get retrieves a flag by key. Returns (nil, nil) if not found. All other transport errors are surfaced to the caller.
func (*Store) IsEnabled ¶
IsEnabled checks if a flag is enabled. Returns false if not found or on transport errors (caller can use Get to distinguish).