redis

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyNotFound

func KeyNotFound(err error) bool

KeyNotFound will detect whether error signifies key not found by Redis.

Types

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
	Get(ctx context.Context, key string) (string, error)
	SetStruct(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	GetStruct(ctx context.Context, key string, target interface{}) error
	Delete(ctx context.Context, key string) error
}

Cache interface specifies the methods implemented for Redis caching. String key and interface{} value are the supported types.

type Connection

type Connection struct {
	Client  *redis.Client
	Options Options
}

func NewClient

func NewClient(options Options) *Connection

func (*Connection) Delete

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

Delete executes the redis Del command

func (*Connection) Get

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

Get executes the redis Get command

func (*Connection) GetStruct

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

GetStruct executes the redis Get command

func (*Connection) Ping

func (connection *Connection) Ping(ctx context.Context) error

Ping tests connectivity for redis (PONG should be returned)

func (*Connection) Set

func (c *Connection) Set(ctx context.Context, key string, value string, expiration time.Duration) error

Set executes the redis Set command

func (*Connection) SetStruct

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

SetStruct executes the redis Set command

type Options

type Options struct {
	Address                  string
	Password                 string
	DB                       int
	DefaultDurationInSeconds int
}

func DefaultOptions

func DefaultOptions() Options

func (*Options) GetDefaultDuration

func (opt *Options) GetDefaultDuration() time.Duration

Jump to

Keyboard shortcuts

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