redis

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 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 upserts a given object with a key to it.
	SetStruct(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	// GetStruct fetches a given object given a key.
	GetStruct(ctx context.Context, key string, target interface{}) error
	// Delete removes the object given a key.
	Delete(ctx context.Context, keys ...string) error
	// Ping is a utility function to check if connection is good.
	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
}

Connection contains Redis client connection object and the Options used to connect.

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 {
	// Redis server(cluster) address.
	Address string
	// Password required when connecting to the Redis server.
	Password string
	// DB to connect to.
	DB int
	// DefaultDurationInSeconds specifies the default caching time to use if not specified on call.
	DefaultDurationInSeconds int
	// TLS config.
	TLSConfig *tls.Config
}

Redis configurable options.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions.

func (*Options) GetDefaultDuration

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

Returns the default duration.

Jump to

Keyboard shortcuts

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