Documentation ¶
Index ¶
- Constants
- Variables
- func FavoriteMoveToDB() error
- func GetAllUserIDs(ctx context.Context, videoID int64) ([]int64, error)
- func GetFollowerIDs(ctx context.Context, userID int64) (*[]int64, error)
- func GetFollowingIDs(ctx context.Context, userID int64) (*[]int64, error)
- func GetMessageTimestamp(ctx context.Context, token string, toUserID int64) (int, error)
- func GetUserFollowers(ctx context.Context, userID int64, userIDs []int64) (*[]*RelationCache, error)
- func GetUserFollowings(ctx context.Context, userID int64, userIDs []int64) (*[]*RelationCache, error)
- func GoCronFavorite()
- func GoCronRelation()
- func LockByMutex(ctx context.Context, mutex *redsync.Mutex) error
- func NewRedisHelper() *redis.Client
- func RelationMoveToDB() error
- func SetMessageTimestamp(ctx context.Context, token string, toUserID int64, timestamp int) error
- func UnlockByMutex(ctx context.Context, mutex *redsync.Mutex) error
- func UpdateFavorite(ctx context.Context, favorite *FavoriteCache) error
- func UpdateRelation(ctx context.Context, relation *RelationCache) error
- type FavoriteCache
- type RedisHelper
- type RelationCache
Constants ¶
View Source
const ExpireTime = 6 * time.Second
Variables ¶
View Source
var ( FavoriteMutex *redsync.Mutex RelationMutex *redsync.Mutex )
Functions ¶
func FavoriteMoveToDB ¶
func FavoriteMoveToDB() error
func GetFollowerIDs ¶
GetFollowerIDs 根据用户ID获取粉丝ID列表
func GetFollowingIDs ¶
GetFollowingIDs 根据用户ID获取关注者ID列表
func GetMessageTimestamp ¶
func GetUserFollowers ¶
func GetUserFollowers(ctx context.Context, userID int64, userIDs []int64) (*[]*RelationCache, error)
GetUserFollowers 根据该用户的ID和从Redis获取后的userIDs,获取该用户的粉丝RelationCache列表
func GetUserFollowings ¶
func GetUserFollowings(ctx context.Context, userID int64, userIDs []int64) (*[]*RelationCache, error)
GetUserFollowings 根据该用户的ID和从Redis获取后的userIDs,获取该用户的关注者RelationCache列表
func GoCronFavorite ¶
func GoCronFavorite()
func GoCronRelation ¶
func GoCronRelation()
func LockByMutex ¶
LockByMutex Obtain a lock for our given mutex. After this is successful, no one else can obtain the same lock (the same mutex name) until we unlock it.
func NewRedisHelper ¶
func NewRedisHelper() *redis.Client
func RelationMoveToDB ¶
func RelationMoveToDB() error
func SetMessageTimestamp ¶
func UnlockByMutex ¶
UnlockByMutex Release the lock so other processes or threads can obtain a lock.
func UpdateFavorite ¶
func UpdateFavorite(ctx context.Context, favorite *FavoriteCache) error
* UpdateFavorite * ActionType == 1 点赞;ActionType == 2 取消点赞 * 1. 使用集合set来存储被点赞类型的id,Key为video+被点赞视频的id,Value为点赞的用户id列表 * 2. set存储某个类型点赞的记录,Key为video::vid::user::uid,hashKey为点赞视频+点赞人,Value为action_type
func UpdateRelation ¶
func UpdateRelation(ctx context.Context, relation *RelationCache) error
UpdateRelation 更新关系
Types ¶
type FavoriteCache ¶
type FavoriteCache struct { VideoID uint `json:"video_id" redis:"video_id"` UserID uint `json:"user_id" redis:"user_id"` ActionType uint `json:"action_type" redis:"action_type"` // 若redis中vid-uid相应的action_type=2,则表示取消点赞,不插入数据库 CreatedAt uint `json:"created_at" redis:"created_at"` }
func GetUsersFavorites ¶
func GetUsersFavorites(ctx context.Context, videoID int64, userIDs []int64) ([]*FavoriteCache, error)
*
- GetUsersFavorites
- 根据多个hashKey获取对应值
- video::<video_id>::user::<user_id> -> FavoriteCache
type RedisHelper ¶
type RedisHelper struct {
*redis.Client
}
func GetRedisHelper ¶
func GetRedisHelper() *RedisHelper
Click to show internal directories.
Click to hide internal directories.