valkey

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) func(gas.ConfigProvider, gas.Logger) *Service

New captures options and returns a DI-injectable constructor.

Types

type Config

type Config struct {
	env.WithGasEnv

	Cache Settings
}

Config holds Valkey cache settings.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the Config for correctness.

type Option

type Option func(*Service)

Option configures a Service.

func WithConfig

func WithConfig(cfg *Config) Option

WithConfig sets a custom configuration.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a Valkey-backed cache implementing gas.Service and gas.CacheProvider.

func (*Service) CheckHealth

func (s *Service) CheckHealth(_ context.Context) error

CheckHealth reports liveness. The valkey-go client reconnects internally, so a transient network failure is not a liveness failure; only a closed service is.

func (*Service) CheckReady

func (s *Service) CheckReady(ctx context.Context) error

CheckReady reports readiness by pinging the Valkey server with the caller's context.

func (*Service) Client

func (s *Service) Client() valkey.Client

Client returns the underlying valkey.Client for advanced operations.

func (*Service) Close

func (s *Service) Close() error

Close shuts down the Valkey client.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, key string) error

Delete removes a key from the cache.

func (*Service) Exists

func (s *Service) Exists(ctx context.Context, key string) (bool, error)

Exists checks whether a key exists in the cache.

func (*Service) Get

func (s *Service) Get(ctx context.Context, key string) ([]byte, error)

Get returns the value for the given key, or cache.ErrKeyNotFound if the key does not exist.

func (*Service) Init

func (s *Service) Init() error

Init validates the configuration, creates the Valkey client, and verifies connectivity.

func (*Service) Name

func (s *Service) Name() string

Name returns the service identifier.

func (*Service) Set

func (s *Service) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value with the given TTL. If ttl is 0, the key is set without expiration.

type Settings

type Settings struct {
	// Addr is the Valkey server address in host:port format.
	Addr string

	// Password is the authentication password. Empty means no auth.
	//nolint:gosec // intentional
	Password string

	// DB is the database number to use (0-15).
	DB int

	// DialTimeout is the timeout for establishing new connections.
	DialTimeout time.Duration

	// WriteTimeout is applied to net.Conn.SetDeadline and controls
	// the maximum duration for write operations and periodic PINGs.
	WriteTimeout time.Duration

	// ConnRetries is the number of times to retry connecting on failure.
	// 0 means no retries (fail immediately).
	ConnRetries int

	// ConnRetryInterval is the base interval between connection retry
	// attempts. The interval doubles after each failed attempt.
	ConnRetryInterval time.Duration
}

Settings represents the configuration for the Valkey cache.

Jump to

Keyboard shortcuts

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