redis

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Marshaler allows you to specify custom marshaler if needed. Defaults to the SOP default marshaler.

Functions

func CloseConnection

func CloseConnection()

Close the singleton connection if open.

func FormatLockKey

func FormatLockKey(k string) string

Add prefix to the lock key so it becomes unique.

func IsConnectionInstantiated

func IsConnectionInstantiated() bool

Returns true if connection instance is valid.

func KeyNotFound

func KeyNotFound(err error) bool

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

func Lock

func Lock(ctx context.Context, duration time.Duration, lockKeys ...*LockKeys) error

Lock a set of keys.

func Unlock

func Unlock(ctx context.Context, lockKeys ...*LockKeys) error

Unlock a set of keys.

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, keys ...string) error
	Ping(ctx context.Context) error
}

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

func NewClient

func NewClient() Cache

Checks if Redis connection is open and returns the client interface if it is, otherwise returns an error.

func NewMockClient added in v1.6.9

func NewMockClient() Cache

Returns a new Redis mock client.

type Connection

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

func OpenConnection added in v1.6.4

func OpenConnection(options Options) (*Connection, error)

Creates a singleton connection and returns it for every call.

type LockKeys

type LockKeys struct {
	// contains filtered or unexported fields
}

LockKeys contain fields to allow locking and unlocking of a set of redis keys.

func CreateLockKeys

func CreateLockKeys(keys []string) []*LockKeys

Create a set of lock keys.

type Options

type Options struct {
	Address                  string
	Password                 string
	DB                       int
	DefaultDurationInSeconds int
	TLSConfig                *tls.Config
}

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