cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HealthyMessage       = "elasticache is OK"
	ErrEmptySessionID    = errors.New("session id required but was empty")
	ErrEmptySessionEmail = errors.New("session email required but was empty")
	ErrEmptySession      = errors.New("session is empty")
	ErrEmptyAddress      = errors.New("address is empty")
	ErrEmptyPassword     = errors.New("password is empty")
	ErrInvalidTTL        = errors.New("ttl should not be zero")
	ErrSessionNotFound   = errors.New("session not found")
)

Functions

This section is empty.

Types

type Config added in v1.1.0

type Config struct {
	Addr     string
	Password string `json:"-"`
	Database int
	TTL      time.Duration
	TLS      *tls.Config
}

Config - config options for the elasticache client

type ElasticacheClient added in v1.1.0

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

func New added in v1.1.0

func New(c Config) (*ElasticacheClient, error)

New - create new session cache client instance

func (*ElasticacheClient) Checker added in v1.1.0

func (c *ElasticacheClient) Checker(ctx context.Context, state *health.CheckState) error

func (*ElasticacheClient) DeleteAll added in v1.1.0

func (c *ElasticacheClient) DeleteAll() error

DeleteAll - removes all items from elasticache

func (*ElasticacheClient) Expire added in v1.1.0

func (c *ElasticacheClient) Expire(key string, expiration time.Duration) error

Expire - sets the expiration of key

func (*ElasticacheClient) GetByEmail added in v1.1.0

func (c *ElasticacheClient) GetByEmail(email string) (*session.Session, error)

GetByEmail - gets a session from elasticache by the email address. Returns cache.ErrSessionNotFound if a session with the specified email does not exist.

func (*ElasticacheClient) GetByID added in v1.1.0

func (c *ElasticacheClient) GetByID(id string) (*session.Session, error)

GetByID - gets a session from elasticache by the Session ID. Returns cache.ErrSessionNotFound if the session with the specified ID does not exist.

func (*ElasticacheClient) Ping added in v1.1.0

func (c *ElasticacheClient) Ping() error

Ping - checks the connection to elasticache

func (*ElasticacheClient) SetSession added in v1.1.0

func (c *ElasticacheClient) SetSession(s *session.Session) error

SetSession - add session to elasticache

type RedisClienter added in v1.1.0

type RedisClienter interface {
	Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	Get(key string) *redis.StringCmd
	Expire(key string, expiration time.Duration) *redis.BoolCmd
	FlushAll() *redis.StatusCmd
	Ping() *redis.StatusCmd
}

RedisClienter - interface for redis

type RedisClienterMock added in v1.1.0

type RedisClienterMock struct {
	// ExpireFunc mocks the Expire method.
	ExpireFunc func(key string, expiration time.Duration) *redis.BoolCmd

	// FlushAllFunc mocks the FlushAll method.
	FlushAllFunc func() *redis.StatusCmd

	// GetFunc mocks the Get method.
	GetFunc func(key string) *redis.StringCmd

	// PingFunc mocks the Ping method.
	PingFunc func() *redis.StatusCmd

	// SetFunc mocks the Set method.
	SetFunc func(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	// contains filtered or unexported fields
}

RedisClienterMock is a mock implementation of RedisClienter.

    func TestSomethingThatUsesRedisClienter(t *testing.T) {

        // make and configure a mocked RedisClienter
        mockedRedisClienter := &RedisClienterMock{
            ExpireFunc: func(key string, expiration time.Duration) *redis.BoolCmd {
	               panic("mock out the Expire method")
            },
            FlushAllFunc: func() *redis.StatusCmd {
	               panic("mock out the FlushAll method")
            },
            GetFunc: func(key string) *redis.StringCmd {
	               panic("mock out the Get method")
            },
            PingFunc: func() *redis.StatusCmd {
	               panic("mock out the Ping method")
            },
            SetFunc: func(key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
	               panic("mock out the Set method")
            },
        }

        // use mockedRedisClienter in code that requires RedisClienter
        // and then make assertions.

    }

func (*RedisClienterMock) Expire added in v1.1.0

func (mock *RedisClienterMock) Expire(key string, expiration time.Duration) *redis.BoolCmd

Expire calls ExpireFunc.

func (*RedisClienterMock) ExpireCalls added in v1.1.0

func (mock *RedisClienterMock) ExpireCalls() []struct {
	Key        string
	Expiration time.Duration
}

ExpireCalls gets all the calls that were made to Expire. Check the length with:

len(mockedRedisClienter.ExpireCalls())

func (*RedisClienterMock) FlushAll added in v1.1.0

func (mock *RedisClienterMock) FlushAll() *redis.StatusCmd

FlushAll calls FlushAllFunc.

func (*RedisClienterMock) FlushAllCalls added in v1.1.0

func (mock *RedisClienterMock) FlushAllCalls() []struct {
}

FlushAllCalls gets all the calls that were made to FlushAll. Check the length with:

len(mockedRedisClienter.FlushAllCalls())

func (*RedisClienterMock) Get added in v1.1.0

func (mock *RedisClienterMock) Get(key string) *redis.StringCmd

Get calls GetFunc.

func (*RedisClienterMock) GetCalls added in v1.1.0

func (mock *RedisClienterMock) GetCalls() []struct {
	Key string
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedRedisClienter.GetCalls())

func (*RedisClienterMock) Ping added in v1.1.0

func (mock *RedisClienterMock) Ping() *redis.StatusCmd

Ping calls PingFunc.

func (*RedisClienterMock) PingCalls added in v1.1.0

func (mock *RedisClienterMock) PingCalls() []struct {
}

PingCalls gets all the calls that were made to Ping. Check the length with:

len(mockedRedisClienter.PingCalls())

func (*RedisClienterMock) Set added in v1.1.0

func (mock *RedisClienterMock) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Set calls SetFunc.

func (*RedisClienterMock) SetCalls added in v1.1.0

func (mock *RedisClienterMock) SetCalls() []struct {
	Key        string
	Value      interface{}
	Expiration time.Duration
}

SetCalls gets all the calls that were made to Set. Check the length with:

len(mockedRedisClienter.SetCalls())

type SessionCache added in v1.1.0

type SessionCache interface {
	SetSession(s *session.Session) error
	GetByID(ID string) (*session.Session, error)
	GetByEmail(email string) (*session.Session, error)
	DeleteAll() error
}

SessionCache interface for storing and retrieving sessions

Jump to

Keyboard shortcuts

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