cache

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeStandalone = "standalone"
	ModeCluster    = "cluster"
	ModeAuto       = "auto"
)

Variables

View Source
var ErrNotFound = errors.New("valkey: key not found")

ErrNotFound is returned when a key does not exist in Valkey.

Functions

This section is empty.

Types

type Client added in v0.1.12

type Client struct {
	Connection goredis.UniversalClient
}

func CreateNewRedisClient

func CreateNewRedisClient(config RedisConfig) *Client

func (*Client) ClusterNodes added in v0.1.12

func (c *Client) ClusterNodes() *goredis.StringCmd

func (*Client) DeleteHash added in v0.1.12

func (c *Client) DeleteHash(key string, fields ...string) *goredis.IntCmd

func (*Client) DeleteListElements added in v0.1.12

func (c *Client) DeleteListElements(key string) *goredis.StringCmd

func (*Client) DeleteSet added in v0.1.12

func (c *Client) DeleteSet(key string) *goredis.StringCmd

func (*Client) DeleteString added in v0.1.12

func (c *Client) DeleteString(key string) *goredis.StringCmd

Works only with Redis >= 6.2.0, use `SetStringWithExpiry` with versions lower than 6.2

func (*Client) Get added in v0.1.12

func (c *Client) Get(key string) *goredis.StringCmd

func (*Client) GetHashVals added in v0.1.12

func (c *Client) GetHashVals(key string) *goredis.StringSliceCmd

func (*Client) GetListRange added in v0.1.12

func (c *Client) GetListRange(key string, start, end int64) *goredis.StringSliceCmd

func (*Client) GetSetMembers added in v0.1.12

func (c *Client) GetSetMembers(key string) *goredis.StringSliceCmd

func (*Client) Info added in v0.1.12

func (c *Client) Info() *goredis.StringCmd

func (*Client) Set added in v0.1.12

func (c *Client) Set(key, value string) *goredis.StatusCmd

func (*Client) SetAdd added in v0.1.12

func (c *Client) SetAdd(key string, members interface{}) *goredis.IntCmd

func (*Client) SetHash added in v0.1.12

func (c *Client) SetHash(key string, values interface{}) *goredis.IntCmd

func (*Client) SetListContents added in v0.1.12

func (c *Client) SetListContents(key string, values interface{}) *goredis.IntCmd

func (*Client) SetStringWithExpiry added in v0.1.12

func (c *Client) SetStringWithExpiry(key string, value string, expiration time.Duration) *goredis.StatusCmd

Using with versions lower than 6.2.0 to delete string after specified time

type Option added in v0.2.13

type Option func(*config)

Option configures ValkeyCache.

func WithAuth added in v0.2.13

func WithAuth(username, password string) Option

WithAuth sets the username and password for Valkey AUTH.

func WithTLS added in v0.2.13

func WithTLS(tlsConfig *tls.Config) Option

WithTLS enables TLS with the given configuration.

type RedisConfig added in v0.1.12

type RedisConfig struct {
	Enabled                            bool
	Url                                string
	Username                           string
	Password                           string
	OperationMode                      string
	MaxActiveConnections               int
	MaxIdleConnections                 int
	IdleTimeoutInSeconds               int
	CrashAppOnConnectionFailure        bool
	ConnectRetryIntervalInSeconds      int
	AutoExpireTopLevelKeysAfterSeconds int
	AppNamespace                       string
}

type SetOption added in v0.2.13

type SetOption func(*setOptions)

SetOption configures the Set operation (e.g., expiration).

func WithExpiration added in v0.2.13

func WithExpiration(d time.Duration) SetOption

WithExpiration sets the expiration for the key.

type ValkeyCache added in v0.2.13

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

ValkeyCache is an idiomatic Go wrapper around valkey-go for standalone Valkey servers.

func NewValkeyCache added in v0.2.13

func NewValkeyCache(host, port string, opts ...Option) (*ValkeyCache, error)

NewValkeyCache creates a new ValkeyCache instance connected to the given host and port. Supports optional configuration via functional options (e.g., WithAuth, WithTLS).

func (*ValkeyCache) Close added in v0.2.13

func (c *ValkeyCache) Close()

Close closes the underlying Valkey client and releases resources.

func (*ValkeyCache) Get added in v0.2.13

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

Get retrieves the string value for a key. Returns ErrNotFound if the key does not exist.

func (*ValkeyCache) LPop added in v0.2.13

func (c *ValkeyCache) LPop(ctx context.Context, key string) (string, error)

LPop pops a value from the head of the list at key. Returns ErrNotFound if the list is empty or the key does not exist.

func (*ValkeyCache) LPush added in v0.2.13

func (c *ValkeyCache) LPush(ctx context.Context, key string, values ...string) (int64, error)

LPush pushes values to the head of the list at key. Returns the new length of the list.

func (*ValkeyCache) LRange added in v0.2.13

func (c *ValkeyCache) LRange(ctx context.Context, key string, start, stop int64) ([]string, error)

LRange returns the elements of the list at key between start and stop (inclusive). Returns an empty slice if the key does not exist.

func (*ValkeyCache) RPop added in v0.2.13

func (c *ValkeyCache) RPop(ctx context.Context, key string) (string, error)

RPop pops a value from the tail of the list at key. Returns ErrNotFound if the list is empty or the key does not exist.

func (*ValkeyCache) RPush added in v0.2.13

func (c *ValkeyCache) RPush(ctx context.Context, key string, values ...string) (int64, error)

RPush pushes values to the tail of the list at key. Returns the new length of the list.

func (*ValkeyCache) Set added in v0.2.13

func (c *ValkeyCache) Set(ctx context.Context, key, value string, opts ...SetOption) error

Set sets the string value for a key, optionally with expiration.

func (*ValkeyCache) Underlying added in v0.2.13

func (c *ValkeyCache) Underlying() valkey.Client

Underlying returns the underlying valkey.Client for advanced use.

type ValkeyCacheAPI added in v0.2.13

type ValkeyCacheAPI interface {
	Set(ctx context.Context, key, value string, opts ...SetOption) error
	Get(ctx context.Context, key string) (string, error)
	LPush(ctx context.Context, key string, values ...string) (int64, error)
	RPush(ctx context.Context, key string, values ...string) (int64, error)
	LPop(ctx context.Context, key string) (string, error)
	RPop(ctx context.Context, key string) (string, error)
	LRange(ctx context.Context, key string, start, stop int64) ([]string, error)
	Close()
	// Underlying returns the underlying valkey.Client for advanced use.
	Underlying() valkey.Client
}

ValkeyCacheAPI defines the interface for the cache wrapper. Useful for dependency injection and testing.

Jump to

Keyboard shortcuts

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