cache

package
v0.0.0-...-674a536 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisAddr             = "127.0.0.1:6379"
	RedisPw               = "" // no password set
	RedisDB               = 0  // use default DB
	RedisMaxRetries       = 3  // retry number for each get/put operation
	RedisReConnMaxRetries = 3  // retry number for creating redis client
	// RedisMinRetryBackoff is min backoff between each retry. -1 disables backoff.
	RedisMinRetryBackoff = 128 * time.Millisecond
	// RedisMaxRetryBackoff is max backoff between each retry. -1 disables backoff.
	RedisMaxRetryBackoff = 512 * time.Millisecond
	// RedisDialTimeout is the timeout for establishing new connections.
	RedisDialTimeout = 5 * time.Second
	// RedisReadTimeout Timeout for socket reads.
	RedisReadTimeout = 3 * time.Second
	// RedisWriteTimeout Timeout for socket writes.
	RedisWriteTimeout   = 3 * time.Second
	RedisKeyDuration    = 48 * time.Hour
	RedisReConnInterval = 15 * time.Second
)

Variables

This section is empty.

Functions

func Del

func Del(key string) error

Del is a wrapper for redis.Client.Del. It supports asynchronously try to reset the connection to Redis if it fails to delete data.

func Get

func Get(key string) ([]byte, error)

Get is a wrapper for redis.Client.Get. It supports asynchronously try to reset the connection to Redis if it fails to get data. If the key doesn't exist in Redis, it returns an empty byte array together with a redis.Nil error

func GetRedisClient

func GetRedisClient() *redis.Client

GetRedisClient returns a global instance of redis.Client in singleton model.

func GetRedisConfig

func GetRedisConfig() *redis.Options

GetRedisConfig returns the global configurationo of Redis in singleton model.

func IsConnected

func IsConnected() bool

IsConnected calls redis.Client.Ping() to verify the connection to Redis.

func ResetRedisClient

func ResetRedisClient()

ResetRedisClient tries to reset the connection to Redis.

func Set

func Set(key string, val interface{}, keyDuration time.Duration) error

Set is a wrapper for redis.Client.Set. It supports asynchronously try to reset the connection to Redis if it fails to set data.

func SetBytes

func SetBytes(key string, val []byte, keyDuration time.Duration) error

Types

type Map

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Map is a go-built in map data structure with a read-write lock.

func GetCacheMap

func GetCacheMap() *Map

GetCacheMap is a singleton methond and return the global instance of map cache.

func (*Map) Add

func (instance *Map) Add(k string, v interface{})

Add is to insert data into map cache.

func (*Map) Contains

func (instance *Map) Contains(k string) bool

Contains returns if the map cache contains the key.

func (*Map) StartClean

func (instance *Map) StartClean(interval time.Duration, maxDuration float64)

StartClean starts a goroutine to clean the data of cache in some interval.

Jump to

Keyboard shortcuts

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