cache

package
v0.0.0-...-e06565c Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBNotInit = errors.New("redis client not init")
	ErrNotFound  = errors.New("key not found")
)
View Source
var (
	ErrLockTimeout = errors.New("lock timeout")
)

Functions

func AutoDelete

func AutoDelete[T any](key string, context ...redis.Cmdable) (int64, error)

Delete the value with key

func AutoGet

func AutoGet[T any](key string, context ...redis.Cmdable) (*T, error)

Get the value with key

func AutoGetWithGetter

func AutoGetWithGetter[T any](key string, getter func() (*T, error), context ...redis.Cmdable) (*T, error)

Get the value with key, fallback to getter if not found, and set the value to cache

func AutoSet

func AutoSet[T any](key string, value T, context ...redis.Cmdable) error

Set the value with key

func Close

func Close() error

Close the redis client

func Decrease

func Decrease(key string, context ...redis.Cmdable) (int64, error)

Decrease the key

func Del

func Del(key string, context ...redis.Cmdable) (int64, error)

Del the key

func DelMapField

func DelMapField(key string, field string, context ...redis.Cmdable) error

DelMapField delete the map field with key

func Exist

func Exist(key string, context ...redis.Cmdable) (int64, error)

Exist check the key exist or not

func Expire

func Expire(key string, time time.Duration, context ...redis.Cmdable) (bool, error)

func Get

func Get[T any](key string, context ...redis.Cmdable) (*T, error)

Get the value with key

func GetMap

func GetMap[V any](key string, context ...redis.Cmdable) (map[string]V, error)

GetMap get the map with key

func GetMapField

func GetMapField[T any](key string, field string, context ...redis.Cmdable) (*T, error)

GetMapField get the map field with key

func GetMapFieldString

func GetMapFieldString(key string, field string, context ...redis.Cmdable) (string, error)

GetMapFieldString get the string

func GetString

func GetString(key string, context ...redis.Cmdable) (string, error)

GetString get the string with key

func Increase

func Increase(key string, context ...redis.Cmdable) (int64, error)

Increase the key

func InitRedisClient

func InitRedisClient(addr, username, password string, useSsl bool, db int) error

func InitRedisSentinelClient

func InitRedisSentinelClient(sentinels []string, masterName, username, password, sentinelUsername, sentinelPassword string, useSsl bool, db int, socketTimeout float64) error

func Lock

func Lock(key string, expire time.Duration, tryLockTimeout time.Duration, context ...redis.Cmdable) error

Lock key, expire time takes responsibility for expiration time try_lock_timeout takes responsibility for the timeout of trying to lock

func Publish

func Publish(channel string, message any, context ...redis.Cmdable) error

func ScanKeys

func ScanKeys(match string, context ...redis.Cmdable) ([]string, error)

ScanKeys scan the keys with match pattern

func ScanKeysAsync

func ScanKeysAsync(match string, fn func([]string) error, context ...redis.Cmdable) error

ScanKeysAsync scan the keys with match pattern, format like "key*"

func ScanMap

func ScanMap[V any](key string, match string, context ...redis.Cmdable) (map[string]V, error)

ScanMap scan the map with match pattern, format like "key*"

func ScanMapAsync

func ScanMapAsync[V any](key string, match string, fn func(map[string]V) error, context ...redis.Cmdable) error

ScanMapAsync scan the map with match pattern, format like "key*"

func SetExpire

func SetExpire(key string, time time.Duration, context ...redis.Cmdable) error

SetExpire set the expire time for the key

func SetMapField

func SetMapField(key string, v map[string]any, context ...redis.Cmdable) error

SetMapField set the map field with key

func SetMapOneField

func SetMapOneField(key string, field string, value any, context ...redis.Cmdable) error

SetMapOneField set the map field with key

func SetNX

func SetNX[T any](key string, value T, expire time.Duration, context ...redis.Cmdable) (bool, error)

SetNX set the key-value pair with expire time

func Store

func Store(key string, value any, time time.Duration, context ...redis.Cmdable) error

Store the key-value pair

func Subscribe

func Subscribe[T any](channel string) (<-chan T, func())

func Transaction

func Transaction(fn func(redis.Pipeliner) error) error

func Unlock

func Unlock(key string, context ...redis.Cmdable) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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