database

package
v0.0.0-...-41c3b62 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EMPTY_GIFT = 1 //空奖品(“谢谢参与”)的ID

Variables

This section is empty.

Functions

func ClearOrders

func ClearOrders() error

清除全部订单记录

func GetAllGiftsV2

func GetAllGiftsV2(ch chan<- Gift)

千万级以上大表遍历方案。 更多数据库调优经验参见《go数据库编程大全》(https://www.bilibili.com/cheese/play/ss5727)。

func GetGiftDBConnection

func GetGiftDBConnection() *gorm.DB

func GetRedisClient

func GetRedisClient() *redis.Client

func InitGiftInventory

func InitGiftInventory()

从Mysql中读出所有奖品的初始库存,存入Redis。如果同时有很多用户来参与抽奖活动,不能交发去Mysql里减库存,mysql扛不住这么高的并发量,Redis可以扛住

func ReduceInventory

func ReduceInventory(GiftId int) error

奖品对应的库存减1

Types

type Gift

type Gift struct {
	Id      int    `gorm:"column:id;primaryKey"`
	Name    string `gorm:"column:name"`
	Price   int    `gorm:"column:price"`
	Picture string `gorm:"column:picture"`
	Count   int    `gorm:"column:count"`
}

func GetAllGiftInventory

func GetAllGiftInventory() []*Gift

获取所有奖品剩余的库存量

func GetAllGiftsV1

func GetAllGiftsV1() []*Gift

func (Gift) TableName

func (Gift) TableName() string

type Order

type Order struct {
	Id     int
	GiftId int
	UserId int
}

Jump to

Keyboard shortcuts

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