cache

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderEtcd   = "etcd"
	ProviderRedis  = "redis"
	ProviderMemory = "memory"
)
View Source
const (
	Redis         = "redis"
	RedisSentinel = "redis-sentinel"
	RedisCluster  = "redis-cluster"
)
View Source
const NoExpiration time.Duration = 0

Variables

View Source
var ErrNotExists = fmt.Errorf("key not exists")

Functions

func IsNotExists

func IsNotExists(e error) bool

Types

type Interface

type Interface interface {
	Set(key, value string, expire time.Duration) error
	Update(key, newValue string) error
	Get(key string) (value string, err error)
	Exist(key string) (bool, error)
	Remove(key string) error
	Expire(key string, expire time.Duration) error
}

func NewEtcd

func NewEtcd(reader iam.TokenReader, writer iam.TokenWriter) (Interface, error)

func NewMemory

func NewMemory() (Interface, error)

func NewRedis

func NewRedis(opt *RedisOptions) (Interface, error)

type Options

type Options struct {
	CacheProvider string        `json:"cacheProvider" yaml:"cacheProvider"`
	RedisOptions  *RedisOptions `json:"redis,omitempty" yaml:"redis,omitempty" mapstructure:"redis"`
}

func NewEtcdOptions

func NewEtcdOptions() *Options

func (*Options) AddFlags

func (s *Options) AddFlags(fs *pflag.FlagSet)

func (*Options) Validate

func (s *Options) Validate() []error

type RedisOptions

type RedisOptions struct {
	// redis schema. one of redis redis-sentinel cluster
	Schema string `json:"schema"`

	Addrs    []string `json:"addrs" yaml:"addrs"`
	Username string   `json:"username" yaml:"username"`
	Password string   `json:"password" yaml:"password"`
	DB       int      `json:"db" yaml:"db"`

	MasterName       string `json:"masterName" yaml:"masterName"`
	SentinelUsername string `json:"sentinelUsername" yaml:"sentinelUsername"`
	SentinelPassword string `json:"sentinelPassword" yaml:"sentinelPassword"`

	Prefix string `json:"prefix" yaml:"prefix"`
}

func NewRedisOptions

func NewRedisOptions() *RedisOptions

func (*RedisOptions) AddFlags

func (s *RedisOptions) AddFlags(fs *pflag.FlagSet)

AddFlags specified FlagSet

func (*RedisOptions) Validate

func (s *RedisOptions) Validate() []error

Jump to

Keyboard shortcuts

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