redis

package
v0.0.0-...-f77d796 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	Fetch(context.Context, Key, Thunk) Result
	Ping(context.Context) *redis.StatusCmd
}

Connection provides an interface for the connection used for fetching Redis keys

func New

func New(options *Options) Connection

New returns a new RealConnection instance

func NewTestConnection

func NewTestConnection(options *Options) Connection

NewTestConnection returns a TestConnection instance, which satisfies the Connection interface and can be used in tests

type Key

type Key string

Key is used for looking something up in Redis

func NewKey

func NewKey(funcName string, identifier string) Key

NewKey creates a Redis key

type Options

type Options = redis.Options

Options is an alias for go-redis options

type RealConnection

type RealConnection struct {
	*redis.Client
}

RealConnection handles a Redis connection

func (*RealConnection) Fetch

func (c *RealConnection) Fetch(ctx context.Context, key Key, thunk Thunk) Result

Fetch returns whatever is found in Redis for `key`, and, if nothing is found, execute the thunk, save the value to Redis and return the result.

type Result

type Result struct {
	Payload *string
	Err     error
}

Result is the return value for a Redis lookup

func (Result) Success

func (r Result) Success() bool

Success returns true if the lookup was a success

type TestConnection

type TestConnection struct{}

TestConnection is a fake connection used for testing

func (*TestConnection) Fetch

func (c *TestConnection) Fetch(ctx context.Context, key Key, thunk Thunk) Result

Fetch allows the call to go to the database and return the result

func (*TestConnection) Ping

func (c *TestConnection) Ping(ctx context.Context) *redis.StatusCmd

Ping pretends to ping the Redis instance

type Thunk

type Thunk func() (*string, error)

Thunk is a closure over code that will produce a result if the value cannot be found in Redis

Jump to

Keyboard shortcuts

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