rediscache

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rediscache provides a Redis-backed cache.Store implementation.

Example:

import (
	"github.com/goforj/cache"
	"github.com/goforj/cache/driver/rediscache"
)

store := rediscache.New(rediscache.Config{
	Addr:   "127.0.0.1:6379",
	Prefix: "app",
})
c := cache.NewCache(store)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) cachecore.Store

New builds a Redis-backed cachecore.Store.

Defaults: - DefaultTTL: 5*time.Minute when zero - Prefix: "app" when empty - Addr: empty by default (no client auto-created unless Addr is set) - Client: optional advanced override (takes precedence when set) - If neither Client nor Addr is set, operations return errors until a client is provided

Example: explicit Redis driver config

store := rediscache.New(rediscache.Config{
	BaseConfig: cachecore.BaseConfig{
		DefaultTTL: 5 * time.Minute,
		Prefix:     "app",
	},
	Addr: "127.0.0.1:6379",
})
fmt.Println(store.Driver()) // redis

Types

type Client

type Client interface {
	Ping(ctx context.Context) *redis.StatusCmd
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
	IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd
}

Client captures the subset of redis.Client used by the store.

type Config

type Config struct {
	cachecore.BaseConfig
	Addr      string
	Username  string
	Password  string
	DB        int
	TLSConfig *tls.Config
	Client    Client
}

Config configures a Redis-backed cache store.

Jump to

Keyboard shortcuts

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