adapter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrInvalidTTL = errors.New("invalid TTL")

ErrInvalidTTL is returned when TTL is invalid.

View Source
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) Decr

func (a *RedisCacheAdapter) Decr(ctx context.Context, key string) (int64, error)

Decr decrements a counter.

func (*RedisCacheAdapter) Delete

func (a *RedisCacheAdapter) Delete(ctx context.Context, key string) error

Delete removes a key.

func (*RedisCacheAdapter) DeletePattern

func (a *RedisCacheAdapter) DeletePattern(ctx context.Context, pattern string) (int64, error)

DeletePattern deletes all keys matching a pattern.

func (*RedisCacheAdapter) Exists

func (a *RedisCacheAdapter) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists.

func (*RedisCacheAdapter) Expire

func (a *RedisCacheAdapter) Expire(ctx context.Context, key string, ttl time.Duration) error

Expire sets expiration on a key.

func (*RedisCacheAdapter) Get

func (a *RedisCacheAdapter) Get(ctx context.Context, key string) (string, error)

Get retrieves a value by key.

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) Incr

func (a *RedisCacheAdapter) Incr(ctx context.Context, key string) (int64, error)

Incr increments a counter.

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.

func (*RedisCacheAdapter) TTL

TTL returns remaining TTL for a key.

Jump to

Keyboard shortcuts

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