Version: v0.0.0-...-5dc576f Latest Latest

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

Go to latest
Published: Dec 11, 2020 License: GPL-3.0 Imports: 7 Imported by: 0




This section is empty.


View Source
var (
	// ErrNoCache represents a "Cache not found" error.
	ErrNoCache = errors.New("Cache not found")
	// ErrFailedCommand represents a "Failed command" error.
	ErrFailedCommand = errors.New("Failed command")
View Source
var (
	DefaultCacheTTL = 24 * time.Hour


func IsErrFailedCommand

func IsErrFailedCommand(err error) bool

IsErrFailedCommand checks if the given error is a "Failed command" error.

func IsErrNoCache

func IsErrNoCache(err error) bool

IsErrNoCache checks if the given error is a "Cache not found" error.


type Connection

type Connection struct {
	Client *redisv8.Client

	DebugMode bool
	// contains filtered or unexported fields

Connection stores Redis connection client & information.

func NewConnection

func NewConnection(conf RedisConfig) (*Connection, error)

NewConnection creates new basic Redis connection.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the client, releasing any open resources.

func (*Connection) DeleteCache

func (c *Connection) DeleteCache(ctx context.Context, key string) error

DeleteCache deletes a single cache with the specified key.

func (*Connection) DeleteCacheByPrefix

func (c *Connection) DeleteCacheByPrefix(ctx context.Context, prefix string) error

DeleteCacheByPrefix deletes multiple caches that matched the given prefix key.

func (*Connection) GetCache

func (c *Connection) GetCache(ctx context.Context, key string, value interface{}) error

GetCache gets cache for the specified key and assign the result to value.

func (*Connection) LogError

func (c *Connection) LogError(err error, msg string)

LogError prints Redis connection error log to stderr.

func (*Connection) LogWarn

func (c *Connection) LogWarn(err error, msg string)

LogWarn prints Redis connection warning log to stdout.

func (*Connection) SetCache

func (c *Connection) SetCache(
	ctx context.Context, key string, value interface{}, ttl time.Duration,
) error

SetCache caches an object using the specified key.

type RedisConfig

type RedisConfig struct {
	Host      string
	Port      string
	Username  string
	Password  string
	Namespace string
	DBNumber  int
	DebugMode bool

RedisConfig stores Redis common connection config.

Source Files

Jump to

Keyboard shortcuts

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