Documentation
¶
Index ¶
Constants ¶
View Source
const ( ReadCount = "read_count" LikeCount = "like_count" CollectCount = "collect_count" )
View Source
const CountKey = "sms:%s:%s"
View Source
const LockedKey = "sms_locked:%s"
View Source
const (
SCRIPTPATH = "./script/commit.lua"
)
View Source
const VCodeKey = "sms:%s:%s"
Variables ¶
View Source
var ( ErrCacheEmpty = errors.New("本地缓存为空") ErrCacheExpired = errors.New("本地缓存已过期") )
View Source
var ( ErrMarshalPost = errors.New("序列化帖子失败") ErrUnmarshalPost = errors.New("反序列化帖子失败") ErrSetCache = errors.New("设置缓存失败") ErrGetCache = errors.New("获取缓存失败") )
View Source
var (
ErrCacheMiss = errors.New("cache miss")
)
View Source
var (
ErrKeyNotExist = redis.Nil
)
Functions ¶
This section is empty.
Types ¶
type CheckCache ¶
type CheckCache interface { GetCache(ctx context.Context, key string) (*domain.Check, error) SetCache(ctx context.Context, key string, check domain.Check, ttl time.Duration) error ClearCache(ctx context.Context, key string) error DeleteKeysWithPattern(ctx context.Context, pattern string) error GetCacheList(ctx context.Context, key string) ([]domain.Check, error) SetCacheList(ctx context.Context, key string, checks []domain.Check, ttl time.Duration) error GetCountCache(ctx context.Context, key string) (int64, error) SetCountCache(ctx context.Context, key string, count int64, ttl time.Duration) error GenerateCacheKey(id interface{}) string GeneratePaginationCacheKey(pagination domain.Pagination) string GenerateCountCacheKey() string }
func NewCheckCache ¶
func NewCheckCache(client redis.Cmdable) CheckCache
type CommentCache ¶
type CommentCache interface { Get(ctx context.Context, postId int64) (domain.Comment, error) Set(ctx context.Context, du domain.Comment) error }
func NewCommentCache ¶
func NewCommentCache(cmd redis.Cmdable) CommentCache
type EmailCache ¶
type EmailCache interface { GetVCode(ctx context.Context, email string) (string, error) StoreVCode(ctx context.Context, email, vCode string) error }
func NewEmailCache ¶
func NewEmailCache(client redis.Cmdable) EmailCache
type HistoryCache ¶
type HistoryCache interface { SetCache(ctx context.Context, history domain.History) error GetCache(ctx context.Context, pagination domain.Pagination) ([]domain.History, error) DeleteOneCache(ctx context.Context, postId uint, uid int64) error DeleteAllHistory(ctx context.Context, uid int64) error }
func NewHistoryCache ¶
func NewHistoryCache(logger *zap.Logger, client redis.Cmdable) HistoryCache
type InteractiveCache ¶
type InteractiveCache interface { PostReadCountRecord(ctx context.Context, postId uint) error // 阅读计数 PostLikeCountRecord(ctx context.Context, postId uint) error // 点赞计数 DecrLikeCountRecord(ctx context.Context, postId uint) error // 取消点赞 PostCollectCountRecord(ctx context.Context, postId uint) error // 收藏计数 DecrCollectCountRecord(ctx context.Context, postId uint) error // 取消收藏 Get(ctx context.Context, postId uint) (domain.Interactive, error) // 获取互动信息 Set(ctx context.Context, postId uint, res domain.Interactive) error // 存储互动信息 }
func NewInteractiveCache ¶
func NewInteractiveCache(client redis.Cmdable) InteractiveCache
type LotteryDrawCache ¶
type LotteryDrawCache interface { // GetLotteryDraw 从缓存中获取指定ID的抽奖活动 GetLotteryDraw(ctx context.Context, id int) (domain.LotteryDraw, error) // SetLotteryDraw 将抽奖活动设置到缓存中 SetLotteryDraw(ctx context.Context, draw domain.LotteryDraw) error // DeleteLotteryDraw 从缓存中删除指定ID的抽奖活动 DeleteLotteryDraw(ctx context.Context, id int) error // GetLotteryDrawWithLock 在缓存未命中时,使用分布式锁从数据库获取并设置缓存 GetLotteryDrawWithLock(ctx context.Context, id int, fetchFromDB func() (domain.LotteryDraw, error)) (domain.LotteryDraw, error) // GetSecondKillEvent 从缓存中获取指定ID的秒杀活动 GetSecondKillEvent(ctx context.Context, id int) (domain.SecondKillEvent, error) // SetSecondKillEvent 将秒杀活动设置到缓存中 SetSecondKillEvent(ctx context.Context, event domain.SecondKillEvent) error // DeleteSecondKillEvent 从缓存中删除指定ID的秒杀活动 DeleteSecondKillEvent(ctx context.Context, id int) error // GetSecondKillEventWithLock 在缓存未命中时,使用分布式锁从数据库获取并设置缓存 GetSecondKillEventWithLock(ctx context.Context, id int, fetchFromDB func() (domain.SecondKillEvent, error)) (domain.SecondKillEvent, error) }
func NewLotteryDrawCache ¶
func NewLotteryDrawCache(client redis.Cmdable, logger *zap.Logger) LotteryDrawCache
type PostCache ¶
type PostCache interface { Get(ctx context.Context, id int64) (domain.Post, error) Set(ctx context.Context, post domain.Post) error Del(ctx context.Context, id int64) error PreHeat(ctx context.Context, posts []domain.Post) error GetList(ctx context.Context, page int, size int) ([]domain.Post, error) SetList(ctx context.Context, page int, size int, posts []domain.Post) error DelList(ctx context.Context, key string) error GetPubList(ctx context.Context, page int, size int) ([]domain.Post, error) SetPubList(ctx context.Context, page int, size int, posts []domain.Post) error DelPubList(ctx context.Context, key string) error GetPub(ctx context.Context, key string) (domain.Post, error) SetPub(ctx context.Context, key string, post domain.Post) error DelPub(ctx context.Context, key string) error SetEmpty(ctx context.Context, id int64) error // 新增缓存空对象方法 }
func NewPostCache ¶
func NewPostCache(client redis.Cmdable) PostCache
type RankingLocalCache ¶
type RankingLocalCache interface { Set(ctx context.Context, posts []domain.Post) error Get(ctx context.Context) ([]domain.Post, error) ForceGet(ctx context.Context) ([]domain.Post, error) }
func NewRankingLocalCache ¶
func NewRankingLocalCache(logger *zap.Logger) RankingLocalCache
type RankingRedisCache ¶
type RankingRedisCache interface { Set(ctx context.Context, posts []domain.Post) error Get(ctx context.Context) ([]domain.Post, error) }
func NewRankingRedisCache ¶
func NewRankingRedisCache(client redis.Cmdable, logger *zap.Logger) RankingRedisCache
type RedisEXCmd ¶
type RedisEXCmd interface { AddCommand(args ...string) //添加redis命令 Exec() error //执行具有修改性的redis命令,失败自动回滚 Rollback() //可调用完成回滚 }
func NewRedisCmd ¶
func NewRedisCmd(cmd redis.Cmdable) RedisEXCmd
type RelationCache ¶
type RelationCache interface { GetCache(ctx context.Context, key string) ([]domain.Relation, error) SetCache(ctx context.Context, key string, relations []domain.Relation, ttl time.Duration) error GetCountCache(ctx context.Context, key string) (int64, error) SetCountCache(ctx context.Context, key string, count int64, ttl time.Duration) error ClearFollowCache(ctx context.Context, followerID, followeeID int64) error GenerateCacheKey(userID int64, relationType string, pagination domain.Pagination) string GenerateCountCacheKey(userID int64, relationType string) string }
func NewRelationCache ¶
func NewRelationCache(client redis.Cmdable) RelationCache
type SMSCache ¶
type SMSCache interface { GetVCode(ctx context.Context, smsID, number string) (string, error) StoreVCode(ctx context.Context, smsID, number string, vCode string) error SetNX(ctx context.Context, number string, value interface{}, expiration time.Duration) (*redis.BoolCmd, error) Exist(ctx context.Context, number string) bool Count(ctx context.Context, number string) int IncrCnt(ctx context.Context, number string) error ReleaseLock(ctx context.Context, number string) error }
func NewSMSCache ¶
func NewSMSCache(client redis.Cmdable) SMSCache
Click to show internal directories.
Click to hide internal directories.