Documentation
¶
Overview ¶
Package redis provides a Redis integration block with a typed caching API.
Index ¶
- type Block
- func (b *Block) Delete(ctx context.Context, keys ...string) error
- func (b *Block) Exists(ctx context.Context, key string) (bool, error)
- func (b *Block) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (b *Block) Get(ctx context.Context, key string) (string, error)
- func (b *Block) GetJSON(ctx context.Context, key string, v any) error
- func (b *Block) HGet(ctx context.Context, key, field string) (string, error)
- func (b *Block) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (b *Block) HSet(ctx context.Context, key string, fields ...any) error
- func (b *Block) Init(ctx context.Context) error
- func (b *Block) Name() string
- func (b *Block) Set(ctx context.Context, key string, value any, ttl time.Duration) error
- func (b *Block) SetJSON(ctx context.Context, key string, v any, ttl time.Duration) error
- func (b *Block) Shutdown(_ context.Context) error
- type Option
- func WithAddr(addr string) Option
- func WithDB(db int) Option
- func WithDialTimeout(d time.Duration) Option
- func WithKeyPrefix(prefix string) Option
- func WithPassword(password string) Option
- func WithPoolSize(n int) Option
- func WithReadTimeout(d time.Duration) Option
- func WithTLS(tlsCfg *tls.Config) Option
- func WithWriteTimeout(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block is a Redis integration block.
func New ¶
New creates a new Redis Block.
block := redis.New("cache",
redis.WithAddr("localhost:6379"),
redis.WithPassword("secret"),
redis.WithDB(0),
redis.WithKeyPrefix("myapp:"),
)
func (*Block) Get ¶
Get returns the string value associated with key. Returns core.ErrItemNotFound when the key does not exist.
func (*Block) GetJSON ¶
GetJSON retrieves the value at key and unmarshals it into v. Returns core.ErrItemNotFound when the key does not exist.
func (*Block) HGet ¶
HGet retrieves a single field from the hash at key. Returns core.ErrItemNotFound when the key or field does not exist.
func (*Block) HSet ¶
HSet sets one or more field-value pairs in the hash at key. fields should be passed as alternating field, value pairs:
block.HSet(ctx, "user:1", "name", "Alice", "email", "alice@example.com")
func (*Block) Init ¶
Init implements core.Block. It creates the Redis client and verifies connectivity with a PING command.
type Option ¶
type Option func(*blockConfig)
Option configures a Redis Block.
func WithDialTimeout ¶
WithDialTimeout sets the timeout for establishing new connections.
func WithKeyPrefix ¶
WithKeyPrefix prepends a namespace to every key used by this block. Useful for isolating environments (e.g. "prod:", "staging:").
func WithPassword ¶
WithPassword sets the Redis AUTH password.
func WithPoolSize ¶
WithPoolSize sets the maximum number of idle connections in the pool.
func WithReadTimeout ¶
WithReadTimeout sets the per-command read deadline.
func WithWriteTimeout ¶
WithWriteTimeout sets the per-command write deadline.