cache

package
v0.0.0-...-02d2a03 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeSendTooMany        = errors.New("发送太频繁")
	ErrCodeVerifyTooManyTimes = errors.New("验证码错误或者失败太多次")
	ErrUnKnownForCode         = errors.New("未知错误")
)
View Source
var KeyNotExist = redis.Nil

Functions

This section is empty.

Types

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 NewCodeCache

func NewCodeCache(client redis.Cmdable) CodeCache

type RedisCodeCache

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

func (*RedisCodeCache) Set

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

我觉得这里有问题,code发送太频繁不应该是在redis中进行判断的,应该在前端就不允许它进行发送 不过好像也可以,如果前端允许发送,那么我们就先生成验证码然后进行存储,如果存储失败,就不调用发送短信的接口 然后呢返回给前端一个发送太快的消息

func (*RedisCodeCache) Verify

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

type RedisUserCache

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

func (*RedisUserCache) FindById

func (cache *RedisUserCache) FindById(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 {
	FindById(ctx context.Context, id int64) (domain.User, error)
	Set(ctx context.Context, u domain.User) error
}

func NewUserCache

func NewUserCache(cmd redis.Cmdable) UserCache

面向接口编程,依赖注入,这里的cmd可以是本地的redis,也可以是集群的redis 这里的cmd是一个接口,它的实现是redis.Client和redis.ClusterClient

Jump to

Keyboard shortcuts

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