Documentation
¶
Overview ¶
Package adapter provides hexagonal architecture adapters for the cache package.
Primary Adapters (Driving):
- Handler adapters for HTTP/gRPC endpoints
Secondary Adapters (Driven):
- RedisCacheAdapter implements CachePort
See ADR-001 for full architectural context.
Index ¶
- Variables
- type Config
- type RedisCacheAdapter
- func (a *RedisCacheAdapter) Client() *redis.Client
- func (a *RedisCacheAdapter) Close() error
- func (a *RedisCacheAdapter) Decr(ctx context.Context, key string) (int64, error)
- func (a *RedisCacheAdapter) Delete(ctx context.Context, key string) error
- func (a *RedisCacheAdapter) DeletePattern(ctx context.Context, pattern string) (int64, error)
- func (a *RedisCacheAdapter) Exists(ctx context.Context, key string) (bool, error)
- func (a *RedisCacheAdapter) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (a *RedisCacheAdapter) Get(ctx context.Context, key string) (string, error)
- func (a *RedisCacheAdapter) GetJSON(ctx context.Context, key string, dest interface{}) error
- func (a *RedisCacheAdapter) HealthCheck(ctx context.Context) error
- func (a *RedisCacheAdapter) Incr(ctx context.Context, key string) (int64, error)
- func (a *RedisCacheAdapter) Ping(ctx context.Context) error
- func (a *RedisCacheAdapter) Set(ctx context.Context, key string, value string, ttl time.Duration) error
- func (a *RedisCacheAdapter) SetJSON(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (a *RedisCacheAdapter) SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error)
- func (a *RedisCacheAdapter) SortedSetAdd(ctx context.Context, key string, member string, score float64) error
- func (a *RedisCacheAdapter) SortedSetRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (a *RedisCacheAdapter) SortedSetRemove(ctx context.Context, key string, members ...string) error
- func (a *RedisCacheAdapter) TTL(ctx context.Context, key string) (time.Duration, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidTTL = errors.New("invalid TTL")
ErrInvalidTTL is returned when TTL is invalid.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned when a key does not exist.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Addr string `default:"localhost:6379"`
Password string `default:""`
DB int `default:"0"`
PoolSize int `default:"10"`
MinIdleConns int `default:"5"`
DialTimeout time.Duration `default:"5s"`
ReadTimeout time.Duration `default:"3s"`
WriteTimeout time.Duration `default:"3s"`
}
Config holds Redis cache configuration.
type RedisCacheAdapter ¶
type RedisCacheAdapter struct {
// contains filtered or unexported fields
}
RedisCacheAdapter implements outbound.CachePort using Redis.
func NewRedisCacheAdapter ¶
func NewRedisCacheAdapter(cfg Config) *RedisCacheAdapter
NewRedisCacheAdapter creates a new Redis cache adapter.
func NewRedisCacheAdapterFromClient ¶
func NewRedisCacheAdapterFromClient(client *redis.Client) *RedisCacheAdapter
NewRedisCacheAdapterFromClient creates adapter from existing Redis client.
func (*RedisCacheAdapter) Client ¶
func (a *RedisCacheAdapter) Client() *redis.Client
Client returns the underlying Redis client.
func (*RedisCacheAdapter) Close ¶
func (a *RedisCacheAdapter) Close() error
Close closes the Redis connection.
func (*RedisCacheAdapter) Delete ¶
func (a *RedisCacheAdapter) Delete(ctx context.Context, key string) error
Delete removes a key.
func (*RedisCacheAdapter) DeletePattern ¶
DeletePattern deletes all keys matching a pattern.
func (*RedisCacheAdapter) GetJSON ¶
func (a *RedisCacheAdapter) GetJSON(ctx context.Context, key string, dest interface{}) error
GetJSON retrieves and unmarshals JSON.
func (*RedisCacheAdapter) HealthCheck ¶
func (a *RedisCacheAdapter) HealthCheck(ctx context.Context) error
HealthCheck returns cache health status.
func (*RedisCacheAdapter) Ping ¶
func (a *RedisCacheAdapter) Ping(ctx context.Context) error
Ping checks connectivity.
func (*RedisCacheAdapter) Set ¶
func (a *RedisCacheAdapter) Set(ctx context.Context, key string, value string, ttl time.Duration) error
Set stores a value with TTL.
func (*RedisCacheAdapter) SetJSON ¶
func (a *RedisCacheAdapter) SetJSON(ctx context.Context, key string, value interface{}, ttl time.Duration) error
SetJSON marshals and stores JSON.
func (*RedisCacheAdapter) SetNX ¶
func (a *RedisCacheAdapter) SetNX(ctx context.Context, key string, value string, ttl time.Duration) (bool, error)
SetNX stores a value only if key doesn't exist.
func (*RedisCacheAdapter) SortedSetAdd ¶
func (a *RedisCacheAdapter) SortedSetAdd(ctx context.Context, key string, member string, score float64) error
SortedSetAdd adds to a sorted set.
func (*RedisCacheAdapter) SortedSetRange ¶
func (a *RedisCacheAdapter) SortedSetRange(ctx context.Context, key string, start, stop int64) ([]string, error)
SortedSetRange retrieves sorted set members by rank.
func (*RedisCacheAdapter) SortedSetRemove ¶
func (a *RedisCacheAdapter) SortedSetRemove(ctx context.Context, key string, members ...string) error
SortedSetRemove removes from a sorted set.