cache

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheTtl5s  = time.Second * 5
	CacheTtl10s = time.Second * 10
	CacheTtl15s = time.Second * 15
	CacheTtl30s = time.Second * 30

	CacheTtl1m  = time.Minute
	CacheTtl2m  = time.Minute * 2
	CacheTtl5m  = time.Minute * 5
	CacheTtl10m = time.Minute * 10
	CacheTtl15m = time.Minute * 15
	CacheTtl30m = time.Minute * 30

	CacheTtl1h  = time.Hour
	CacheTtl3h  = time.Hour * 3
	CacheTtl6h  = time.Hour * 6
	CacheTtl9h  = time.Hour * 9
	CacheTtl12h = time.Hour * 12

	CacheTtl1d  = time.Hour * 24
	CacheTtl2d  = CacheTtl1d * 2
	CacheTtl3d  = CacheTtl1d * 3
	CacheTtl4d  = CacheTtl1d * 4
	CacheTtl7d  = CacheTtl1d * 7
	CacheTtl9d  = CacheTtl1d * 9
	CacheTtl10d = CacheTtl1d * 10
	CacheTtl15d = CacheTtl1d * 15
	CacheTtl30d = CacheTtl1d * 30
)
View Source
const (
	KeyNotFound     = "key not found"
	ErrorClearCache = "fail to clean cache %s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	GetHost() string
	GetPort() int
	GetUser() string
	GetPassword() string
	GetDatabase() string
}

Config Interface With Methods to be a database config

type Redis

type Redis struct {
	Client *redisClient.Client
	// contains filtered or unexported fields
}

Redis struct to manage redis.

func NewRedis

func NewRedis(config Config) (*Redis, error)

NewRedis is responsible for building a redis struct instance

func (*Redis) Close

func (r *Redis) Close()

Close is responsible for closing redis connection

func (*Redis) Connect

func (r *Redis) Connect() error

Connect connects on redis database

func (*Redis) CreateForceLogoutKeys added in v1.0.37

func (r *Redis) CreateForceLogoutKeys(duration time.Duration, jwtTokens ...string) error

CreateForceLogoutKeys cria as chaves que serão inseridas no cache e que devem forçar o logout do usuário em outros dispositivos

func (*Redis) Del

func (r *Redis) Del(key string) error

Del delete key.

func (*Redis) DelByKeysPattern

func (r *Redis) DelByKeysPattern(match string) error

DelByKeysPattern DO NOT USE THIS METHOD unless you're absolutely sure about what you're doing! it gets redis keys based on a match pattern using Keys() method and then, using DelMany(), removes these keys from redis cache

func (*Redis) DelByPattern

func (r *Redis) DelByPattern(match string) error

DelByPattern gets redis keys based on a match pattern using Scan() method and then, using DelMany(), removes these keys from redis cache

func (*Redis) DelMany

func (r *Redis) DelMany(keys []string) error

DelMany delete many keys.

func (*Redis) DelManyFormattedKeys added in v1.0.14

func (r *Redis) DelManyFormattedKeys(keys []string) error

DelManyFormattedKeys remove várias chaves já formatadas com o nome do serviço

func (*Redis) Exist

func (r *Redis) Exist(key string) (bool, error)

Exist test if key exists.

func (*Redis) FlushAll

func (r *Redis) FlushAll() error

FlushAll clears all keys in the cache

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

Get get key.

func (*Redis) MSet

func (r *Redis) MSet(keys []string, values []interface{}, duration time.Duration) error

MSet sets multiple key values

func (*Redis) Scan

func (r *Redis) Scan(match string) ([]string, error)

Scan gets redis keys based on a match pattern, something like r.Scan("my_key:*")

func (*Redis) Set

func (r *Redis) Set(key, value string, duration time.Duration) error

Set set key.

Jump to

Keyboard shortcuts

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