razcache

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 2 Imported by: 2

README

type Cache interface {
	Set(key, value string, ttl time.Duration) error
	Get(key string) (string, error)
	Del(key string) error

	GetTTL(key string) (time.Duration, error)
	SetTTL(key string, ttl time.Duration) error

	SubCache(prefix string) Cache

	Close() error
}

type ExtendedCache interface {
	Cache

	LPush(key string, values ...string) error
	RPush(key string, values ...string) error
	LPop(key string, count int) ([]string, error)
	RPop(key string, count int) ([]string, error)
	LLen(key string) (int, error)
	LRange(key string, start, stop int) ([]string, error)

	SAdd(key string, values ...string) error
	SRem(key string, values ...string) error
	SHas(key, value string) (bool, error)
	SLen(key string) (int, error)

	Incr(key string, increment int64) (int64, error)

	SubExtendedCache(prefix string) ExtendedCache
}

// pkg/inmem
func NewInMemCache() Cache
func NewInMemExtendedCache() ExtendedCache

// pkg/redis
func NewRedisCache(redisDSN string) (ExtendedCache, error)
func NewRedisCacheFromClient(client redis.Cmdable) ExtendedCache

// pkg/badger
func NewBadgerCache(dir string) (Cache, error)
func NewBadgerCacheFromDB(db *badger.DB) Cache

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("not found")
	ErrWrongType = errors.New("wrong type")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(key, value string, ttl time.Duration) error
	Get(key string) (string, error)
	Del(key string) error

	GetTTL(key string) (time.Duration, error)
	SetTTL(key string, ttl time.Duration) error

	SubCache(prefix string) Cache

	Close() error
}

func NewPrefixCache

func NewPrefixCache(cache Cache, prefix string) Cache

type ExtendedCache

type ExtendedCache interface {
	Cache

	LPush(key string, values ...string) error
	RPush(key string, values ...string) error
	LPop(key string, count int) ([]string, error)
	RPop(key string, count int) ([]string, error)
	LLen(key string) (int, error)
	LRange(key string, start, stop int) ([]string, error)

	SAdd(key string, values ...string) error
	SRem(key string, values ...string) error
	SHas(key, value string) (bool, error)
	SLen(key string) (int, error)

	Incr(key string, increment int64) (int64, error)

	SubExtendedCache(prefix string) ExtendedCache
}

func NewPrefixExtendedCache

func NewPrefixExtendedCache(cache ExtendedCache, prefix string) ExtendedCache

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

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