Help us shape the future of Go! Take the 2026 Go Developer Survey

valkey

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheClientInterface

type CacheClientInterface interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	Delete(ctx context.Context, keys ...string) error
	Exists(ctx context.Context, key string) (bool, error)
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)
	Expire(ctx context.Context, key string, expiration time.Duration) error
	HSet(ctx context.Context, key string, field string, value interface{}) error
	HGet(ctx context.Context, key string, field string) (string, error)
	HGetAll(ctx context.Context, key string) (map[string]string, error)
	Ping(ctx context.Context) error
	Close() error
}

CacheClientInterface defines the interface for cache operations

type Client

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

Client wraps Valkey (Redis) functionality

func NewClient

func NewClient(cfg Config, logger *slog.Logger) (*Client, error)

NewClient creates a new Valkey client

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, keys ...string) error

Delete deletes one or more keys

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists

func (*Client) Expire

func (c *Client) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire sets an expiration on a key

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (string, error)

Get retrieves a value by key

func (*Client) HGet

func (c *Client) HGet(ctx context.Context, key string, field string) (string, error)

HGet gets a field from a hash

func (*Client) HGetAll

func (c *Client) HGetAll(ctx context.Context, key string) (map[string]string, error)

HGetAll gets all fields from a hash

func (*Client) HSet

func (c *Client) HSet(ctx context.Context, key string, field string, value interface{}) error

HSet sets a field in a hash

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks if the connection is alive

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set sets a value with an optional expiration

func (*Client) SetNX

func (c *Client) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)

SetNX sets a value only if the key does not exist

type Config

type Config struct {
	Address  string
	Username string
	Password string
	DB       int
	PoolSize int
	Timeout  time.Duration
	UseTLS   bool
}

Config holds Valkey client configuration

type NoopClient

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

NoopClient is a no-operation implementation of CacheClientInterface that stores data in memory without using Redis/Valkey. Useful for testing and development without cache infrastructure.

func NewNoopClient

func NewNoopClient(logger *slog.Logger) *NoopClient

NewNoopClient creates a new noop Valkey client

func (*NoopClient) Close

func (c *NoopClient) Close() error

Close clears the in-memory storage

func (*NoopClient) Delete

func (c *NoopClient) Delete(ctx context.Context, keys ...string) error

Delete removes values from in-memory storage

func (*NoopClient) Exists

func (c *NoopClient) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists in in-memory storage

func (*NoopClient) Expire

func (c *NoopClient) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire is a no-op (expiration not tracked in memory)

func (*NoopClient) Get

func (c *NoopClient) Get(ctx context.Context, key string) (string, error)

Get retrieves a value from in-memory storage

func (*NoopClient) HGet

func (c *NoopClient) HGet(ctx context.Context, key string, field string) (string, error)

HGet retrieves a field from a hash

func (*NoopClient) HGetAll

func (c *NoopClient) HGetAll(ctx context.Context, key string) (map[string]string, error)

HGetAll retrieves all fields from a hash

func (*NoopClient) HSet

func (c *NoopClient) HSet(ctx context.Context, key string, field string, value interface{}) error

HSet sets a field in a hash

func (*NoopClient) Ping

func (c *NoopClient) Ping(ctx context.Context) error

Ping always returns nil (no actual connection to check)

func (*NoopClient) Set

func (c *NoopClient) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set stores a value in in-memory storage (expiration is ignored)

func (*NoopClient) SetNX

func (c *NoopClient) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)

SetNX sets a value only if the key doesn't exist

Jump to

Keyboard shortcuts

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