cache

package
v0.0.0-...-6ea431b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeSendTooMany        = errors.New("发送验证码太频繁")
	ErrUnknownForCode         = errors.New("发送验证码遇到未知错误")
	ErrCodeVerifyTooManyTimes = errors.New("验证次数太多")
)
View Source
var ErrKeyNotExist = redis.Nil

ErrKeyNotExist 因为我们目前还是只有一个实现,所以可以保持用别名

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 CodeCache

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

func NewRedisCodeCache

func NewRedisCodeCache(cmd redis.Cmdable) CodeCache

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 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 RedisCodeCache

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

RedisCodeCache 基于 Redis 的实现

func (*RedisCodeCache) Set

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

Set 如果该手机在该业务场景下,验证码不存在(都已经过期),那么发送 如果已经有一个验证码,但是发出去已经一分钟了,允许重发 如果已经有一个验证码,但是没有过期时间,说明有不知名错误 如果已经有一个验证码,但是发出去不到一分钟,不允许重发 验证码有效期 10 分钟

func (*RedisCodeCache) Verify

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

Verify 验证验证码 如果验证码是一致的,那么删除 如果验证码不一致,那么保留的

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

func (cache *RedisUserCache) Delete(ctx context.Context, id int64) error

func (*RedisUserCache) Get

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

func (*RedisUserCache) Set

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

type UserCache

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

func NewRedisUserCache

func NewRedisUserCache(cmd redis.Cmdable) UserCache

NewUserCache A 用到了 B,B 一定是接口 A 用到了 B,B 一定是 A 的字段 A 用到了 B,A 绝对不初始化 B,而是外面注入

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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