ecache

package module
v0.0.0-...-7567983 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

ecache

统一缓存 API

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set 设置一个键值对,并且设置过期时间.
	// 当过期时间为0时,表示永不过期
	Set(ctx context.Context, key string, val any, expiration time.Duration) error
	// SetNX 设置一个键值对如果key不存在则写入反之失败,并且设置过期时间.
	// 当过期时间为0时,表示永不过期
	SetNX(ctx context.Context, key string, val any, expiration time.Duration) (bool, error)
	// Get 返回一个 Value
	// 如果你需要检测 Err,可以使用 Value.Err
	// 如果你需要知道 Key 是否存在,可以使用 Value.KeyNotFound
	Get(ctx context.Context, key string) Value
	// GetSet 设置一个新的值返回老的值 如果key没有老的值仍然设置成功,但是返回 errs.ErrKeyNotExist
	GetSet(ctx context.Context, key string, val string) Value
	// Delete 设置一个或多个键值对,当key不存在时,不计入删除数也不返回错误
	Delete(ctx context.Context, key ...string) (int64, error)
	// LPush 将所有指定值插入存储在 的列表的头部key。
	// 如果key不存在,则在执行推送操作之前将其创建为空列表。当key保存的值不是列表时,将返回错误
	// 默认返回列表的数量
	LPush(ctx context.Context, key string, val ...any) (int64, error)
	// LPop 命令用于移除并返回列表的第一个元素。
	LPop(ctx context.Context, key string) Value
	// SAdd 命令将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略。
	SAdd(ctx context.Context, key string, members ...any) (int64, error)
	// SRem 移除集合中的一个或多个成员元素,不存在的成员元素会被忽略。
	// 返回最终删除了多少个原色
	SRem(ctx context.Context, key string, members ...any) (int64, error)
	// IncrBy 设置一个key并自增 1 或者指定的值
	// 返回增加后的值
	IncrBy(ctx context.Context, key string, value int64) (int64, error)
	// DecrBy 将 key 中储存的数字值减一
	// 返回减少后的值
	DecrBy(ctx context.Context, key string, value int64) (int64, error)
	// IncrByFloat 为 key 中所储存的值加上指定的浮点数增量值。
	// 返回增加后的值
	IncrByFloat(ctx context.Context, key string, value float64) (float64, error)
}

type NamespaceCache

type NamespaceCache struct {
	C         Cache
	Namespace string
}

func (*NamespaceCache) DecrBy

func (c *NamespaceCache) DecrBy(ctx context.Context, key string, value int64) (int64, error)

func (*NamespaceCache) Delete

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

func (*NamespaceCache) Get

func (c *NamespaceCache) Get(ctx context.Context, key string) Value

func (*NamespaceCache) GetSet

func (c *NamespaceCache) GetSet(ctx context.Context, key string, val string) Value

func (*NamespaceCache) IncrBy

func (c *NamespaceCache) IncrBy(ctx context.Context, key string, value int64) (int64, error)

func (*NamespaceCache) IncrByFloat

func (c *NamespaceCache) IncrByFloat(ctx context.Context, key string, value float64) (float64, error)

func (*NamespaceCache) LPop

func (c *NamespaceCache) LPop(ctx context.Context, key string) Value

func (*NamespaceCache) LPush

func (c *NamespaceCache) LPush(ctx context.Context, key string, val ...any) (int64, error)

func (*NamespaceCache) SAdd

func (c *NamespaceCache) SAdd(ctx context.Context, key string, members ...any) (int64, error)

func (*NamespaceCache) SRem

func (c *NamespaceCache) SRem(ctx context.Context, key string, members ...any) (int64, error)

func (*NamespaceCache) Set

func (c *NamespaceCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error

func (*NamespaceCache) SetNX

func (c *NamespaceCache) SetNX(ctx context.Context, key string, val any, expiration time.Duration) (bool, error)

type Value

type Value struct {
	ekit.AnyValue
}

Value 代表一个从缓存中读取出来的值

func (Value) KeyNotFound

func (v Value) KeyNotFound() bool

Directories

Path Synopsis
internal
memory
lru
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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