dao

package
v0.0.0-...-dcbaf51 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MulanPSL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dao is used to offer db interface

Index

Constants

This section is empty.

Variables

View Source
var (
	DB  *gorm.DB
	RDB *redis.Client
)

Functions

func CreateComment

func CreateComment(ctx context.Context, uid, vid int64, content string) error

func CreateFavorite

func CreateFavorite(ctx context.Context, uid, vid int64) error

func CreateFollow

func CreateFollow(ctx context.Context, uid, targetID int64) error

func CreateUser

func CreateUser(ctx context.Context, user User) (int64, error)

CreateUser create user info

func CreateVideo

func CreateVideo(ctx context.Context, video Video) error

func DeleteComment

func DeleteComment(ctx context.Context, uid, cid int64) error

func DeleteFavorite

func DeleteFavorite(ctx context.Context, uid, vid int64) error

func DeleteFollow

func DeleteFollow(ctx context.Context, uid, targetID int64) error

func GetSetInt64List

func GetSetInt64List(ctx context.Context, key string) ([]int64, error)

GetSetInt64List 通过SMembers命令获取set中的所有元素,并转化为id序列,方便后期从mysql中拿到数据

func Init

func Init()

func InitDB

func InitDB()

InitDB 初始化数据库信息

func InitRDB

func InitRDB()

InitRDB 初始化redis信息

func MGetFavoriteVideoIDs

func MGetFavoriteVideoIDs(ctx context.Context, uid int64) (ids []int64, err error)

func MGetFollowOrFansIDs

func MGetFollowOrFansIDs(ctx context.Context, key string, uid int64) (ids []int64, err error)

func QueryCommentCount

func QueryCommentCount(ctx context.Context, vid int64) (int64, error)

func QueryFavoriteCount

func QueryFavoriteCount(ctx context.Context, vid int64) int64

func QueryFollowCount

func QueryFollowCount(ctx context.Context, uid int64) int64

QueryFollowCount 使用redis(SCard命令)查询该用户的关注列表

func QueryFollowerCount

func QueryFollowerCount(ctx context.Context, uid int64) int64

QueryFollowerCount 使用redis查询该用户的粉丝列表

func QueryIsFavorite

func QueryIsFavorite(ctx context.Context, uid, vid int64) bool

func QueryIsFollow

func QueryIsFollow(ctx context.Context, curID, targetID int64) bool

QueryIsFollow 使用redis判断该用户是否已关注

func SetEXOfVideos

func SetEXOfVideos(ctx context.Context, videoList []model.Video, key string, expiration time.Duration) error

SetEXOfVideos 将视频切片对象转化为json并存到redis中,并设置过期时间

Types

type Comment

type Comment struct {
	gorm.Model
	UID     int64  `gorm:"column:uid"`
	VID     int64  `gorm:"column:vid"`
	Content string `gorm:"column:content"`
}

func MGetComments

func MGetComments(ctx context.Context, vid int64) ([]Comment, error)

func (*Comment) TableName

func (m *Comment) TableName() string

type User

type User struct {
	gorm.Model
	Name     string `json:"name,omitempty"`
	Password string `json:"password,omitempty"`
}

User 用户的字段

func GetUserByName

func GetUserByName(ctx context.Context, username string) (*User, error)

GetUserByName get user info by username

func MGetUsers

func MGetUsers(ctx context.Context, userIDs []int64) ([]User, error)

MGetUsers multiple get list of user info

func QueryUser

func QueryUser(ctx context.Context, targetID int64) (*User, error)

QueryUser 查询目标用户的info

func (*User) TableName

func (m *User) TableName() string

type Video

type Video struct {
	gorm.Model
	Title    string `gorm:"column:title"`
	AuthorID int64  `gorm:"column:uid"`
	PlayUrl  string `gorm:"column:play_url"`
	CoverUrl string `gorm:"column:cover_url"`
}

Video 影音视频字段

func MGetVideos

func MGetVideos(ctx context.Context, nextTime int64) ([]Video, error)

MGetVideos 按照时间戳降序查找所有视频

func MGetVideosByIDs

func MGetVideosByIDs(ctx context.Context, vids []int64) ([]Video, error)

func MGetVideosByUID

func MGetVideosByUID(ctx context.Context, uid int64) ([]Video, error)

func MGetVideosFromRedis

func MGetVideosFromRedis(ctx context.Context) ([]Video, error)

MGetVideosFromRedis 按照时间戳降序查找所有视频

func (*Video) TableName

func (m *Video) TableName() string

Jump to

Keyboard shortcuts

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