hotrank

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

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

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

README

热度排行榜

  • 基于redis实现 本质以空间换时间

评论回复计数

  • 基于redis实现

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyError    = errors.New("数量为空")
	LikeExists    = errors.New("用户已点赞")
	LikeNotExists = errors.New("用户未点过赞")
)

Functions

func AddScore

func AddScore(k string, v int64)

AddScore 新增评分标准

func AddScoreAfter

func AddScoreAfter(k string, fc func(call *WorkCall))

AddScoreAfter 新增评分增加成功过后回调

func AddScoreValid

func AddScoreValid(k string, fc func(call *WorkCall) bool)

AddScoreValid 新增事件验证

func GenCommentRedisKey

func GenCommentRedisKey(mid string) string

GenCommentRedisKey 评论计数key

func GenLikeRedisKey

func GenLikeRedisKey(mid string) string

GenLikeRedisKey 生成动态点赞key

Types

type HotCallBase

type HotCallBase struct {
	EventName  string // 事件名
	EventPrice int64  // 操作事件的价格 对应加分数
	FromUserId string // 操作者 新增做功
	ToUserId   string // 接收者 接收做功
	Rdb        *redis.Client
}

HotCallBase 热度计算单条信息基础

type Pair

type Pair struct {
	Key   string
	Value int64
}

type PairList

type PairList []Pair

A slice of Pairs that implements sort.Interface to sort by Value.

func (PairList) Len

func (p PairList) Len() int

func (PairList) Less

func (p PairList) Less(i, j int) bool

func (PairList) Swap

func (p PairList) Swap(i, j int)

type WorkCall

type WorkCall struct {
	HotCallBase
	// contains filtered or unexported fields
}

WorkCall 作品计算

func NewWorkHot

func NewWorkHot(rdb *redis.Client, mid string) *WorkCall

NewWorkHot 新增一个实例

func (*WorkCall) AddHotChange

func (c *WorkCall) AddHotChange(ctx context.Context, eventName, fromUserId, toUserId, cityCode, ip string)

AddHotChange 新增作品热度变化 分享 评论必传toUserId 匿名者访问 必传ip

func (*WorkCall) ChangeLike

func (c *WorkCall) ChangeLike(ctx context.Context, mid string, userId string, add bool) error

ChangeLike 点赞变更 考虑是否变更为bitmap方式

func (*WorkCall) GetAggregationRank

func (c *WorkCall) GetAggregationRank(ctx context.Context) (today float64, city float64, all float64)

GetAggregationRank 聚合排名 所有排名 0是最高

func (*WorkCall) GetAllRandomData

func (c *WorkCall) GetAllRandomData(ctx context.Context, count int64) ([]string, error)

GetAllRandomData 总排行榜获取指定数量随机内容

func (*WorkCall) GetAllRank

func (c *WorkCall) GetAllRank(ctx context.Context) float64

GetAllRank 获取作品的总排名

func (*WorkCall) GetAllTopRank

func (c *WorkCall) GetAllTopRank(ctx context.Context, max int64) ([]string, error)

GetAllTopRank 获取总榜的top k

func (*WorkCall) GetCityCountDistribute

func (c *WorkCall) GetCityCountDistribute(ctx context.Context, cityCode string) map[string]int64

GetCityCountDistribute 获取某个城市区间数量分布情况

func (*WorkCall) GetCityRandomData

func (c *WorkCall) GetCityRandomData(ctx context.Context, count int64, cityCode string) ([]string, error)

GetCityRandomData 获取指定数量的随机城市排行榜数据

func (*WorkCall) GetCityRank

func (c *WorkCall) GetCityRank(ctx context.Context) float64

GetCityRank 获取自己的城市总排名

func (*WorkCall) GetCityRankOfRange

func (c *WorkCall) GetCityRankOfRange(ctx context.Context, Range hotRange) int64

GetCityRankOfRange 获取作品在城市某个区间的排名

func (*WorkCall) GetCommentCount

func (c *WorkCall) GetCommentCount(ctx context.Context, mid string) uint64

GetCommentCount 获取评论计数

func (*WorkCall) GetCountDistribute

func (c *WorkCall) GetCountDistribute(ctx context.Context) map[string]int64

GetCountDistribute 获取总区间数量分布情况

func (*WorkCall) GetCountOfRangeInAll

func (c *WorkCall) GetCountOfRangeInAll(ctx context.Context, Range []hotRange) int64

GetCountOfRangeInAll 获取某个区间的总排行榜数量

func (*WorkCall) GetCountOfRangeInCity

func (c *WorkCall) GetCountOfRangeInCity(ctx context.Context, cityCode string, Range []hotRange) int64

GetCountOfRangeInCity 获取某个区间的城市排行榜数量

func (*WorkCall) GetCountOfTimeRange

func (c *WorkCall) GetCountOfTimeRange(ctx context.Context, timer []time.Time) int64

GetCountOfTimeRange 获取某个时间段排行榜数量

func (*WorkCall) GetDayTopRank

func (c *WorkCall) GetDayTopRank(ctx context.Context, t time.Time, max int64) ([]string, error)

GetDayTopRank 获取指定天数的top k

func (*WorkCall) GetRankOfRange

func (c *WorkCall) GetRankOfRange(ctx context.Context, Range hotRange) int64

GetRankOfRange 获取作品在某个区间的排名

func (*WorkCall) GetTimeRandomData

func (c *WorkCall) GetTimeRandomData(ctx context.Context, count int64, t time.Time) ([]string, error)

GetTimeRandomData 获取某个时间随机内容

func (*WorkCall) GetTimeRank

func (c *WorkCall) GetTimeRank(ctx context.Context, t time.Time) int64

GetTimeRank 获取作品某日排名

func (*WorkCall) GetTimeScore

func (c *WorkCall) GetTimeScore(ctx context.Context, t time.Time) float64

GetTimeScore 获取作品某日分数

func (*WorkCall) GetTodayTopRank

func (c *WorkCall) GetTodayTopRank(ctx context.Context, max int64) ([]string, error)

GetTodayTopRank 获取今日top k

func (*WorkCall) HasLike

func (c *WorkCall) HasLike(ctx context.Context, mid string, userId string) bool

HasLike 获取是否点赞

func (*WorkCall) RunCommentRedisChange

func (c *WorkCall) RunCommentRedisChange(ctx context.Context, mid string, add bool, count int64) error

RunCommentRedisChange 评论计数变更

Jump to

Keyboard shortcuts

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