cache

package
v0.0.0-...-d13da26 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeSendTooMany        = errors.New("发送验证码太频繁")
	ErrCodeVerifyTooManyTimes = errors.New("验证次数太多")
	ErrUnknownForCode         = errors.New("我也不知发生什么了,反正是跟 code 有关")
)
View Source
var ErrKeyNotExist = redis.Nil

Functions

This section is empty.

Types

type ArticleCache

type ArticleCache interface {
	// GetFirstPage 只缓存第第一页的数据
	// 并且不缓存整个 Content
	GetFirstPage(ctx context.Context, author int64) ([]domain.Article, error)
	SetFirstPage(ctx context.Context, author int64, arts []domain.Article) error
	DelFirstPage(ctx context.Context, author int64) error

	Set(ctx context.Context, art domain.Article) error
	Get(ctx context.Context, id int64) (domain.Article, error)

	// SetPub 正常来说,创作者和读者的 Redis 集群要分开,因为读者是一个核心中的核心
	SetPub(ctx context.Context, article domain.Article) error
	GetPub(ctx context.Context, id int64) (domain.Article, error)
}

func NewRedisArticleCache

func NewRedisArticleCache(client redis.Cmdable) ArticleCache

type Cache

type Cache interface {
	Set(ctx context.Context, key string, val any, exp time.Duration) error
	Get(ctx context.Context, key string) ekit.AnyValue
}

type CodeCache

type CodeCache interface {
	Set(ctx context.Context, biz, phone, code string) error
	Verify(ctx context.Context, biz, phone, inputCode string) (bool, error)
}

func NewCodeCache

func NewCodeCache(client redis.Cmdable) CodeCache

type DoubleCache

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

func (*DoubleCache) Get

func (d *DoubleCache) Get(ctx context.Context, key string) ekit.AnyValue

func (*DoubleCache) Set

func (d *DoubleCache) Set(ctx context.Context,
	key string, val any, exp time.Duration) error

type InteractiveCache

type InteractiveCache interface {

	// IncrReadCntIfPresent 如果在缓存中有对应的数据,就 +1
	IncrReadCntIfPresent(ctx context.Context,
		biz string, bizId int64) error
	IncrLikeCntIfPresent(ctx context.Context,
		biz string, bizId int64) error
	DecrLikeCntIfPresent(ctx context.Context,
		biz string, bizId int64) error
	IncrCollectCntIfPresent(ctx context.Context, biz string, bizId int64) error
	// Get 查询缓存中数据
	// 事实上,这里 liked 和 collected 是不需要缓存的
	Get(ctx context.Context, biz string, bizId int64) (domain.Interactive, error)
	Set(ctx context.Context, biz string, bizId int64, intr domain.Interactive) error
}

func NewRedisInteractiveCache

func NewRedisInteractiveCache(client redis.Cmdable) InteractiveCache

type LocalCache

type LocalCache struct {
}

type LocalCodeCache

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

LocalCodeCache 假如说你要切换这个,你是不是得把 lua 脚本的逻辑,在这里再写一遍?

type RankingCache

type RankingCache interface {
	Set(ctx context.Context, arts []domain.Article) error
	Get(ctx context.Context) ([]domain.Article, error)
}

type RankingLocalCache

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

func NewRankingLocalCache

func NewRankingLocalCache() *RankingLocalCache

func (*RankingLocalCache) ForceGet

func (r *RankingLocalCache) ForceGet(ctx context.Context) ([]domain.Article, error)

func (*RankingLocalCache) Get

func (*RankingLocalCache) Set

func (r *RankingLocalCache) Set(ctx context.Context, arts []domain.Article) error

type RankingRedisCache

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

func NewRankingRedisCache

func NewRankingRedisCache(client redis.Cmdable) *RankingRedisCache

func (*RankingRedisCache) Get

func (*RankingRedisCache) Set

func (r *RankingRedisCache) Set(ctx context.Context, arts []domain.Article) error

type RedisArticleCache

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

func (*RedisArticleCache) DelFirstPage

func (r *RedisArticleCache) DelFirstPage(ctx context.Context, author int64) error

func (*RedisArticleCache) Get

func (*RedisArticleCache) GetFirstPage

func (r *RedisArticleCache) GetFirstPage(ctx context.Context, author int64) ([]domain.Article, error)

func (*RedisArticleCache) GetPub

func (r *RedisArticleCache) GetPub(ctx context.Context, id int64) (domain.Article, error)

func (*RedisArticleCache) Set

func (*RedisArticleCache) SetFirstPage

func (r *RedisArticleCache) SetFirstPage(ctx context.Context, author int64, arts []domain.Article) error

func (*RedisArticleCache) SetPub

func (r *RedisArticleCache) SetPub(ctx context.Context, art domain.Article) error

type RedisCache

type RedisCache struct {
}

type RedisCodeCache

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

func NewCodeCacheGoBestPractice

func NewCodeCacheGoBestPractice(client redis.Cmdable) *RedisCodeCache

NewCodeCacheGoBestPractice Go 的最佳实践是返回具体类型

func (*RedisCodeCache) Set

func (c *RedisCodeCache) Set(ctx context.Context, biz, phone, code string) error

func (*RedisCodeCache) Verify

func (c *RedisCodeCache) Verify(ctx context.Context, biz, phone, inputCode string) (bool, error)

type RedisInteractiveCache

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

func (*RedisInteractiveCache) DecrLikeCntIfPresent

func (r *RedisInteractiveCache) DecrLikeCntIfPresent(ctx context.Context,
	biz string, bizId int64) error

func (*RedisInteractiveCache) Get

func (*RedisInteractiveCache) IncrCollectCntIfPresent

func (r *RedisInteractiveCache) IncrCollectCntIfPresent(ctx context.Context,
	biz string, bizId int64) error

func (*RedisInteractiveCache) IncrLikeCntIfPresent

func (r *RedisInteractiveCache) IncrLikeCntIfPresent(ctx context.Context,
	biz string, bizId int64) error

func (*RedisInteractiveCache) IncrReadCntIfPresent

func (r *RedisInteractiveCache) IncrReadCntIfPresent(ctx context.Context,
	biz string, bizId int64) error

func (*RedisInteractiveCache) Set

func (r *RedisInteractiveCache) Set(ctx context.Context, biz string, bizId int64, intr domain.Interactive) error

type RedisUserCache

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

func (*RedisUserCache) Get

func (cache *RedisUserCache) Get(ctx context.Context, id int64) (domain.User, error)

Get 如果没有数据,返回一个特定的 error

func (*RedisUserCache) Set

func (cache *RedisUserCache) Set(ctx context.Context, u domain.User) error

type UserCache

type UserCache interface {
	Get(ctx context.Context, id int64) (domain.User, error)
	Set(ctx context.Context, u domain.User) error
}

func NewUserCache

func NewUserCache(client redis.Cmdable) UserCache

NewUserCache A 用到了 B,B 一定是接口 => 这个是保证面向接口 A 用到了 B,B 一定是 A 的字段 => 规避包变量、包方法,都非常缺乏扩展性 A 用到了 B,A 绝对不初始化 B,而是外面注入 => 保持依赖注入(DI, Dependency Injection)和依赖反转(IOC) expiration 1s, 1m

func NewUserCacheV1

func NewUserCacheV1(addr string) UserCache

Directories

Path Synopsis
Package cachemocks is a generated GoMock package.
Package cachemocks is a generated GoMock package.
Package redismocks is a generated GoMock package.
Package redismocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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