redis

package
v0.0.0-...-f9b5f64 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ExpireTime = 6 * time.Second

Variables

View Source
var (
	FavoriteMutex *redsync.Mutex
	RelationMutex *redsync.Mutex
)

Functions

func FavoriteMoveTomysql

func FavoriteMoveTomysql() error

func GetAllUserIDs

func GetAllUserIDs(ctx context.Context, videoID int64) ([]int64, error)

*

  • GetAllUserIDs
  • 获取所有被点赞类型id的点赞用户id
  • video::<video_id> -> user_id 列表

func GetFollowerIDs

func GetFollowerIDs(ctx context.Context, userID int64) (*[]int64, error)

GetFollowerIDs 根据用户ID获取粉丝ID列表

func GetFollowingIDs

func GetFollowingIDs(ctx context.Context, userID int64) (*[]int64, error)

GetFollowingIDs 根据用户ID获取关注者ID列表

func GetMessageTimestamp

func GetMessageTimestamp(ctx context.Context, token string, toUserID int64) (int, error)

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

func LockByMutex(ctx context.Context, mutex *redsync.Mutex) error

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 RelationMoveTomysql

func RelationMoveTomysql() error

func SetMessageTimestamp

func SetMessageTimestamp(ctx context.Context, token string, toUserID int64, timestamp int) error

func UnlockByMutex

func UnlockByMutex(ctx context.Context, mutex *redsync.Mutex) error

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

type RelationCache

type RelationCache struct {
	UserID     uint `json:"user_id" redis:"user_id"`
	ToUserID   uint `json:"to_user_id" redis:"to_user_id"`
	ActionType uint `json:"action_type" redis:"action_type"`
	CreatedAt  uint `json:"created_at" redis:"created_at"`
}

Jump to

Keyboard shortcuts

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