Documentation
¶
Overview ¶
Package redis provides a source.Reader implementation that reads scripts from a Redis key-value store (or any Redis-compatible server such as Valkey, DragonflyDB, KeyDB, ...).
Construction:
src, err := redis.New(ctx,
redis.WithAddr("localhost:6379"),
redis.WithPrefix("scripts:lua:"),
)
Hot-reload detection uses client-side polling: the value returned by the most recent Load is kept in memory, and Watch polls compare the current value against the stored one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("redis source: key not found")
ErrNotFound is returned (wrapped) by Load when the requested key does not exist in Redis. Detect with errors.Is(err, ErrNotFound) or the convenience helper IsNotFound.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err represents a "key not found" response from Redis. Equivalent to errors.Is(err, ErrNotFound).
Types ¶
type Option ¶
type Option func(*configOptions)
Option configures a Reader. Pass to New.
func WithPassword ¶
WithPassword sets the Redis password for AUTH.
func WithPrefix ¶
WithPrefix sets a key prefix that is transparently prepended to every key before it is resolved against Redis. Useful when all scripts share a common namespace (e.g. WithPrefix("scripts:lua:")).
Leading slashes are stripped; no other normalization is applied so callers can use any separator (":", "/", etc.).
func WithUsername ¶
WithUsername sets the Redis username (Redis ACL, since Redis 6.0).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads scripts from Redis.
All exported methods are safe for concurrent use. Reader implements the source.ReadWatcher interface.
func New ¶
New creates a Redis-backed Reader. All settings are optional; defaults are "localhost:6379", DB 0, no password.
Credentials can be supplied via WithPassword / WithUsername. For Redis ACL users, set both username and password.
func (*Reader) Load ¶
Load fetches the value from Redis and returns it as a string. Context cancellation propagates to the underlying request.
A redis.Nil response is reported as a wrapped ErrNotFound. Other errors are wrapped with the key for easier debugging.
func (*Reader) Watch ¶
Watch returns a channel that signals when the value identified by `key` changes. It polls the value every 5 seconds and sends a signal on the channel when the value differs from the one recorded during the last Load.
The returned channel is closed when the context is cancelled. Callers should re-Load the script after receiving from the channel.