remotecache

package
v0.0.0-...-31d061a Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Nil = redis.Nil

Nil is the error value in case the specified key does not exist

Functions

func Get

func Get[T any](ctx context.Context, client *redis.Client, key string) (T, error)

Get the specified key. Returns Nil as error if not present

func GetOrCreate

func GetOrCreate[T any](ctx context.Context, rc *Client, key string, valueFactory func(*Options) (T, error)) (T, error)

GetOrCreate the cache entry

func Release

func Release(ctx context.Context, lock RemoteLock)

Release the lock with logging the error occuring

func Set

func Set[T any](ctx context.Context, client *redis.Client, key string, value T, ttl time.Duration) error

Set the specified key to the provided value with ttl.

Types

type Client

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

Client contains the client and locker

func New

func New(client *redis.Client, locker *redislock.Client) *Client

New remote cache struct

func (*Client) Client

func (rc *Client) Client() *redis.Client

Client returns the redis client

func (*Client) Lock

func (rc *Client) Lock(ctx context.Context, key string) (RemoteLock, error)

Lock returns a new lock

func (*Client) Locker

func (rc *Client) Locker() *redislock.Client

Locker returns the redis locker

type Options

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

Options are definable options for caching an entry

func (*Options) SetTTL

func (o *Options) SetTTL(ttl time.Duration)

SetTTL sets the relative expiration of the key

type RemoteLock

type RemoteLock interface {
	Release(context.Context) error
}

RemoteLock is a lock that can be released

func Lock

func Lock(ctx context.Context, locker *redislock.Client, key string) (RemoteLock, error)

Lock the specified key and get a release method in return

Jump to

Keyboard shortcuts

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