cache

package
v0.0.0-...-e2755d2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Consul constant for getting ConsulClient from Cache factory
	Consul = "consul"
	// Redis constant for getting Redis cache client
	Redis = "redis"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver       string
	ConsulConfig ConsulConfig
	RedisConfig  RedisConfig
}

Config holds cache configuration

type ConsulClient

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

ConsulClient ...

func (*ConsulClient) Delete

func (c *ConsulClient) Delete(ctx context.Context, key string) error

Delete deletes a single key from consul.

func (*ConsulClient) Get

func (c *ConsulClient) Get(ctx context.Context, key string) ([]byte, error)

Get fetches from consul. If key does not exist, empty value is returned.

func (*ConsulClient) IsAlive

func (c *ConsulClient) IsAlive(_ context.Context) (bool, error)

IsAlive checks the health of consul.

func (*ConsulClient) Set

func (c *ConsulClient) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set calls the PUT api to set a value in consul.

type ConsulConfig

type ConsulConfig struct {
	api.Config
}

ConsulConfig ...

type ICache

type ICache interface {
	// Get a key from cache.
	Get(ctx context.Context, key string) ([]byte, error)
	// Set a key in cache.
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	// Delete a key in cache.
	Delete(ctx context.Context, key string) error
	// IsAlive performs a healthcheck on the cache.
	IsAlive(context.Context) (bool, error)
}

ICache is an interface for implementing cache.

func NewCache

func NewCache(config *Config) (ICache, error)

NewCache initializes the cache instance based on Config

func NewConsulClient

func NewConsulClient(config *ConsulConfig) (ICache, error)

NewConsulClient creates a new consul client

type RedisClient

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

RedisClient ...

func NewRedisClient

func NewRedisClient(config *RedisConfig) (*RedisClient, error)

NewRedisClient ...

func (*RedisClient) Delete

func (rc *RedisClient) Delete(ctx context.Context, key string) error

Delete ...

func (*RedisClient) Disconnect

func (rc *RedisClient) Disconnect() error

Disconnect ... disconnects from the redis server

func (*RedisClient) Get

func (rc *RedisClient) Get(ctx context.Context, key string) ([]byte, error)

Get ...

func (*RedisClient) IsAlive

func (rc *RedisClient) IsAlive(ctx context.Context) (bool, error)

IsAlive ...

func (*RedisClient) MGet

func (rc *RedisClient) MGet(keys ...string) ([]interface{}, error)

MGet ...

func (*RedisClient) Set

func (rc *RedisClient) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set ...

type RedisConfig

type RedisConfig struct {
	Host     string
	Port     string
	Database int32
	Password string
}

RedisConfig holds all required info for initializing redis driver

Jump to

Keyboard shortcuts

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