cache

package
v0.0.0-...-8845ca5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFound = errors.New("key not found")

Functions

func GetFiberStorage

func GetFiberStorage(storage Cache) fiber.Storage

Types

type BaseCache

type BaseCache interface {
	Get(key string) (string, error)

	Set(key string, value any) error
	SetEx(key string, value any, timeout time.Duration) error
	SetNx(key string, value interface{}) (bool, error)
	SetNxWithTimeout(key string, value interface{}, timeout time.Duration) (bool, error)

	Ttl(key string) (time.Duration, error)
	Expire(key string, timeout time.Duration) (bool, error)

	Incr(key string) (int64, error)
	Decr(key string) (int64, error)
	IncrBy(key string, value int64) (int64, error)
	DecrBy(key string, value int64) (int64, error)

	Exists(keys ...string) (bool, error)

	HSet(key string, field string, value interface{}) (bool, error)
	HGet(key, field string) (string, error)
	HDel(key string, fields ...string) (int64, error)
	HKeys(key string) ([]string, error)
	HGetAll(key string) (map[string]string, error)
	HExists(key string, field string) (bool, error)
	HIncr(key string, subKey string) (int64, error)
	HIncrBy(key string, field string, increment int64) (int64, error)
	HDecr(key string, field string) (int64, error)
	HDecrBy(key string, field string, increment int64) (int64, error)

	SAdd(key string, members ...string) (int64, error)
	SMembers(key string) ([]string, error)
	SRem(key string, members ...string) (int64, error)
	SRandMember(key string, count ...int64) ([]string, error)
	SPop(key string) (string, error)
	SisMember(key, field string) (bool, error) // 成员是否存在

	Del(key ...string) error

	Close() error
}

type Bbolt

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

func (*Bbolt) Close

func (p *Bbolt) Close() error

func (*Bbolt) Decr

func (p *Bbolt) Decr(key string) (int64, error)

func (*Bbolt) DecrBy

func (p *Bbolt) DecrBy(key string, value int64) (int64, error)

func (*Bbolt) Del

func (p *Bbolt) Del(key ...string) error

func (*Bbolt) Exists

func (p *Bbolt) Exists(keys ...string) (bool, error)

func (*Bbolt) Expire

func (p *Bbolt) Expire(key string, timeout time.Duration) (bool, error)

func (*Bbolt) Get

func (p *Bbolt) Get(key string) (string, error)

func (*Bbolt) HDecr

func (p *Bbolt) HDecr(key string, field string) (int64, error)

func (*Bbolt) HDecrBy

func (p *Bbolt) HDecrBy(key string, field string, increment int64) (int64, error)

func (*Bbolt) HDel

func (p *Bbolt) HDel(key string, fields ...string) (int64, error)

func (*Bbolt) HExists

func (p *Bbolt) HExists(key string, field string) (bool, error)

func (*Bbolt) HGet

func (p *Bbolt) HGet(key, field string) (string, error)

func (*Bbolt) HGetAll

func (p *Bbolt) HGetAll(key string) (map[string]string, error)

func (*Bbolt) HIncr

func (p *Bbolt) HIncr(key string, subKey string) (int64, error)

func (*Bbolt) HIncrBy

func (p *Bbolt) HIncrBy(key string, field string, increment int64) (int64, error)

func (*Bbolt) HKeys

func (p *Bbolt) HKeys(key string) ([]string, error)

func (*Bbolt) HSet

func (p *Bbolt) HSet(key string, field string, value interface{}) (bool, error)

func (*Bbolt) Incr

func (p *Bbolt) Incr(key string) (int64, error)

func (*Bbolt) IncrBy

func (p *Bbolt) IncrBy(key string, value int64) (int64, error)

func (*Bbolt) Reset

func (p *Bbolt) Reset() error

func (*Bbolt) SAdd

func (p *Bbolt) SAdd(key string, members ...string) (int64, error)

func (*Bbolt) SMembers

func (p *Bbolt) SMembers(key string) ([]string, error)

func (*Bbolt) SPop

func (p *Bbolt) SPop(key string) (string, error)

func (*Bbolt) SRandMember

func (p *Bbolt) SRandMember(key string, count ...int64) ([]string, error)

func (*Bbolt) SRem

func (p *Bbolt) SRem(key string, members ...string) (int64, error)

func (*Bbolt) Set

func (p *Bbolt) Set(key string, value any) error

func (*Bbolt) SetEx

func (p *Bbolt) SetEx(key string, value any, timeout time.Duration) error

func (*Bbolt) SetNx

func (p *Bbolt) SetNx(key string, value interface{}) (bool, error)

func (*Bbolt) SetNxWithTimeout

func (p *Bbolt) SetNxWithTimeout(key string, value interface{}, timeout time.Duration) (bool, error)

func (*Bbolt) SisMember

func (p *Bbolt) SisMember(key, field string) (bool, error)

func (*Bbolt) Ttl

func (p *Bbolt) Ttl(key string) (time.Duration, error)

type Cache

type Cache interface {
	BaseCache

	GetBool(key string) (bool, error)
	GetInt(key string) (int, error)
	GetUint(key string) (uint, error)
	GetInt32(key string) (int32, error)
	GetUint32(key string) (uint32, error)
	GetInt64(key string) (int64, error)
	GetUint64(key string) (uint64, error)
	GetFloat32(key string) (float32, error)
	GetFloat64(key string) (float64, error)

	GetSlice(key string) ([]string, error)
	GetBoolSlice(key string) ([]bool, error)
	GetIntSlice(key string) ([]int, error)
	GetUintSlice(key string) ([]uint, error)
	GetInt32Slice(key string) ([]int32, error)
	GetUint32Slice(key string) ([]uint32, error)
	GetInt64Slice(key string) ([]int64, error)
	GetUint64Slice(key string) ([]uint64, error)
	GetFloat32Slice(key string) ([]float32, error)
	GetFloat64Slice(key string) ([]float64, error)

	GetJson(key string, j interface{}) error

	HGetJson(key, field string, j interface{}) error

	Limit(key string, limit int64, timeout time.Duration) (bool, error)
}

func New

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

func NewBbolt

func NewBbolt(addr string, options *bbolt.Options) (Cache, error)

func NewMem

func NewMem() Cache

func NewRedis

func NewRedis(address string, opts ...redis.DialOption) (Cache, error)

type Config

type Config struct {
	// Cache type, support mem, redis, bbolt, default mem
	Type string `yaml:"type"`

	// Cache address
	// mem: empty
	// redis: redis address, default 127.0.0.1:6379
	// bbolt: bbolt file path, default ./ice.cache
	Address string `yaml:"address"`

	// Cache password
	// mem: empty
	// redis: redis password
	// bbolt: empty
	Password string `yaml:"password"`
}

type FiberStorage

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

func (*FiberStorage) Close

func (p *FiberStorage) Close() error

func (*FiberStorage) Delete

func (p *FiberStorage) Delete(key string) error

func (*FiberStorage) Get

func (p *FiberStorage) Get(key string) ([]byte, error)

func (*FiberStorage) Reset

func (p *FiberStorage) Reset() error

func (*FiberStorage) Set

func (p *FiberStorage) Set(key string, val []byte, exp time.Duration) error

type Item

type Item struct {
	Data string `json:"data,omitempty"`

	ExpireAt time.Time `json:"expire_at,omitempty"`
}

func (*Item) Bytes

func (p *Item) Bytes() []byte

func (*Item) String

func (p *Item) String() string

type Mem

type Mem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Mem) Close

func (p *Mem) Close() error

func (*Mem) Decr

func (p *Mem) Decr(key string) (int64, error)

func (*Mem) DecrBy

func (p *Mem) DecrBy(key string, value int64) (int64, error)

func (*Mem) Del

func (p *Mem) Del(key ...string) error

func (*Mem) Exists

func (p *Mem) Exists(keys ...string) (bool, error)

func (*Mem) Expire

func (p *Mem) Expire(key string, timeout time.Duration) (bool, error)

func (*Mem) Get

func (p *Mem) Get(key string) (string, error)

func (*Mem) HDecr

func (p *Mem) HDecr(key string, field string) (int64, error)

func (*Mem) HDecrBy

func (p *Mem) HDecrBy(key string, field string, increment int64) (int64, error)

func (*Mem) HDel

func (p *Mem) HDel(key string, fields ...string) (int64, error)

func (*Mem) HExists

func (p *Mem) HExists(key string, field string) (bool, error)

func (*Mem) HGet

func (p *Mem) HGet(key, field string) (string, error)

func (*Mem) HGetAll

func (p *Mem) HGetAll(key string) (map[string]string, error)

func (*Mem) HIncr

func (p *Mem) HIncr(key string, subKey string) (int64, error)

func (*Mem) HIncrBy

func (p *Mem) HIncrBy(key string, field string, increment int64) (int64, error)

func (*Mem) HKeys

func (p *Mem) HKeys(key string) ([]string, error)

func (*Mem) HSet

func (p *Mem) HSet(key string, field string, value interface{}) (bool, error)

func (*Mem) Incr

func (p *Mem) Incr(key string) (int64, error)

func (*Mem) IncrBy

func (p *Mem) IncrBy(key string, value int64) (int64, error)

func (*Mem) Reset

func (p *Mem) Reset() error

func (*Mem) SAdd

func (p *Mem) SAdd(key string, members ...string) (int64, error)

func (*Mem) SMembers

func (p *Mem) SMembers(key string) ([]string, error)

func (*Mem) SPop

func (p *Mem) SPop(key string) (string, error)

func (*Mem) SRandMember

func (p *Mem) SRandMember(key string, count ...int64) ([]string, error)

func (*Mem) SRem

func (p *Mem) SRem(key string, members ...string) (int64, error)

func (*Mem) Set

func (p *Mem) Set(key string, val any) error

func (*Mem) SetEx

func (p *Mem) SetEx(key string, value any, timeout time.Duration) error

func (*Mem) SetNx

func (p *Mem) SetNx(key string, value interface{}) (bool, error)

func (*Mem) SetNxWithTimeout

func (p *Mem) SetNxWithTimeout(key string, value interface{}, timeout time.Duration) (bool, error)

func (*Mem) SisMember

func (p *Mem) SisMember(key, field string) (bool, error)

func (*Mem) Ttl

func (p *Mem) Ttl(key string) (time.Duration, error)

type Redis

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

func (*Redis) Close

func (p *Redis) Close() error

func (*Redis) Decr

func (p *Redis) Decr(key string) (int64, error)

func (*Redis) DecrBy

func (p *Redis) DecrBy(key string, value int64) (int64, error)

func (*Redis) Del

func (p *Redis) Del(keys ...string) (err error)

func (*Redis) Exists

func (p *Redis) Exists(keys ...string) (bool, error)

func (*Redis) Expire

func (p *Redis) Expire(key string, timeout time.Duration) (bool, error)

func (*Redis) Get

func (p *Redis) Get(key string) (string, error)

func (*Redis) HDecr

func (p *Redis) HDecr(key string, field string) (int64, error)

func (*Redis) HDecrBy

func (p *Redis) HDecrBy(key string, field string, increment int64) (int64, error)

func (*Redis) HDel

func (p *Redis) HDel(key string, fields ...string) (int64, error)

func (*Redis) HExists

func (p *Redis) HExists(key, field string) (bool, error)

func (*Redis) HGet

func (p *Redis) HGet(key, field string) (string, error)

func (*Redis) HGetAll

func (p *Redis) HGetAll(key string) (map[string]string, error)

func (*Redis) HIncr

func (p *Redis) HIncr(key string, subKey string) (int64, error)

func (*Redis) HIncrBy

func (p *Redis) HIncrBy(key string, field string, increment int64) (int64, error)

func (*Redis) HIncrByFloat

func (p *Redis) HIncrByFloat(key string, field string, increment float64) (float64, error)

func (*Redis) HKeys

func (p *Redis) HKeys(key string) ([]string, error)

func (*Redis) HSet

func (p *Redis) HSet(key string, field string, value interface{}) (bool, error)

func (*Redis) HVals

func (p *Redis) HVals(key string) ([]string, error)

func (*Redis) Incr

func (p *Redis) Incr(key string) (int64, error)

func (*Redis) IncrBy

func (p *Redis) IncrBy(key string, value int64) (int64, error)

func (*Redis) IncrByFloat

func (p *Redis) IncrByFloat(key string, increment float64) (float64, error)

func (*Redis) SAdd

func (p *Redis) SAdd(key string, members ...string) (int64, error)

func (*Redis) SMembers

func (p *Redis) SMembers(key string) ([]string, error)

func (*Redis) SPop

func (p *Redis) SPop(key string) (string, error)

func (*Redis) SRandMember

func (p *Redis) SRandMember(key string, count ...int64) ([]string, error)

func (*Redis) SRem

func (p *Redis) SRem(key string, members ...string) (int64, error)

func (*Redis) Set

func (p *Redis) Set(key string, value interface{}) (err error)

func (*Redis) SetEx

func (p *Redis) SetEx(key string, value interface{}, timeout time.Duration) error

func (*Redis) SetNx

func (p *Redis) SetNx(key string, value interface{}) (bool, error)

func (*Redis) SetNxWithTimeout

func (p *Redis) SetNxWithTimeout(key string, value interface{}, timeout time.Duration) (bool, error)

func (*Redis) SisMember

func (p *Redis) SisMember(key, field string) (bool, error)

func (*Redis) Ttl

func (p *Redis) Ttl(key string) (time.Duration, error)

Jump to

Keyboard shortcuts

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