cache

package
v0.0.0-...-e105d0e Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Consul = "consul"
	Redis  = "redis"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Provider     string
	RedisConfig  RedisConfig
	ConsulConfig ConsulConfig
}

type ConsulClient

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

func (*ConsulClient) Delete

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

func (*ConsulClient) Get

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

func (*ConsulClient) IsAlive

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

func (*ConsulClient) Set

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

type ConsulConfig

type ConsulConfig struct {
	api.Config
}

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)
}

func NewCache

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

NewCache initializes the cache instance based on Config

func NewConsulClient

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

func NewRedisClient

func NewRedisClient(config *RedisConfig, opts ...RedisOption) (ICache, error)

type RedisClient

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

func (*RedisClient) Delete

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

func (*RedisClient) Disconnect

func (rc *RedisClient) Disconnect() error

func (*RedisClient) Get

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

func (*RedisClient) IsAlive

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

func (*RedisClient) MGet

func (rc *RedisClient) MGet(ctx context.Context, keys ...string) ([]any, error)

func (*RedisClient) Set

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

type RedisConfig

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

type RedisOption

type RedisOption func(*RedisClient)

func WithReadTimeout

func WithReadTimeout(t time.Duration) RedisOption

WithReadTimeout set read timeout

func WithWriteTimeout

func WithWriteTimeout(t time.Duration) RedisOption

WithWriteTimeout set write timeout

Jump to

Keyboard shortcuts

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