Documentation ¶
Index ¶
- Variables
- func CloseConnection()
- func FormatLockKey(k string) string
- func IsConnectionInstantiated() bool
- func IsLocked(ctx context.Context, lockKeys ...*LockKeys) error
- func KeyNotFound(err error) bool
- func Lock(ctx context.Context, duration time.Duration, lockKeys ...*LockKeys) error
- func Unlock(ctx context.Context, lockKeys ...*LockKeys) error
- type Cache
- type Connection
- type LockKeys
- type Options
Constants ¶
This section is empty.
Variables ¶
var Marshaler sop.Marshaler = sop.NewMarshaler()
Marshaler allows you to specify custom marshaler if needed. Defaults to the SOP default marshaler.
Functions ¶
func FormatLockKey ¶
Add prefix to the lock key so it becomes unique.
func IsConnectionInstantiated ¶
func IsConnectionInstantiated() bool
Returns true if connection instance is valid.
func KeyNotFound ¶
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 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.
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.
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 (*Options) GetDefaultDuration ¶
Returns the default duration.