list

package
v1.1.40 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package list has some list cache implemented by redis

Index

Constants

View Source
const (
	MaxLoadBatch = 100
)

load const params

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEntity

type BaseEntity struct {
	ID         int64  `column:"id" pk:"Y"` //auto increment id
	OwnerID    string `column:"o_id"`
	TargetID   int64  `column:"t_id"`
	CreateTime int64  `column:"ct"`
}

BaseEntity define the base list entity

func (*BaseEntity) GetCreateTime

func (p *BaseEntity) GetCreateTime() int64

GetCreateTime impls Entity.GetCreateTime

func (*BaseEntity) GetID

func (p *BaseEntity) GetID() int64

GetID implements Entity.GetID()

func (*BaseEntity) GetOwnerID

func (p *BaseEntity) GetOwnerID() string

GetOwnerID implement Entity.GetOwnerID

func (*BaseEntity) GetTargetID

func (p *BaseEntity) GetTargetID() int64

GetTargetID implement Entity.GetTargetID()

func (*BaseEntity) SetCreateTime

func (p *BaseEntity) SetCreateTime(ct int64)

SetCreateTime impls Entity.SetCreateTime

func (*BaseEntity) SetID added in v1.1.27

func (p *BaseEntity) SetID(id int64)

SetID implements Entity.GetID()

func (*BaseEntity) TableName

func (p *BaseEntity) TableName() string

TableName implement Entity.TableName()

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache define the list cache

func NewCache

func NewCache(entityProtoType Entity, dbService func() orm.ShardDBService, redisClient func() *cache.RedisClient, listCacheParam *cache.ParamConf, maxListCount int64, targetIDAsScore bool, counter counter.Counter) (*Cache, error)

NewCache create new Cache

func (*Cache) Add

func (p *Cache) Add(entity Entity) (bool, error)

Add entity to list cache

func (*Cache) Del

func (p *Cache) Del(ownerID string, targetID int64) (bool, error)

Del delete the ownerID, targetID from list cache

func (*Cache) GetCount

func (p *Cache) GetCount(ownerID string) (count int64, err error)

GetCount query the count of the ownerID's list

func (*Cache) GetIDForOwnerTarget

func (p *Cache) GetIDForOwnerTarget(ownerID string, targetID int64) (id int64, err error)

GetIDForOwnerTarget query the Entity.ID with ownerID and targetID

func (*Cache) LoadList

func (p *Cache) LoadList(ownerID string, page, pageSize, cursor int64) (total int64, ids []int64, err error)

LoadList load targetId from list cache

func (*Cache) LoadListWithScore

func (p *Cache) LoadListWithScore(ownerID string, page, pageSize, cursor int64) (total int64, targetAndScores []*IDScore, err error)

LoadListWithScore load targetId and score from list cache

type CounterEntity

type CounterEntity struct {
	counter.BaseEntity
}

CounterEntity is the list counter

func (*CounterEntity) ToBaseEntity

func (p *CounterEntity) ToBaseEntity(counterID string, fields counter.Fields) (*CounterEntity, error)

ToBaseEntity to base entity

func (*CounterEntity) ZeroFields

func (p *CounterEntity) ZeroFields() counter.Fields

ZeroFields implements the EntityCounter.ZeroFields

type Entity

type Entity interface {
	orm.Entity
	// GetID return the id
	GetID() int64
	// SetID
	SetID(int64)
	// GetOwnerID return the owner id
	GetOwnerID() string
	// GetTargetID return the target id
	GetTargetID() int64
	// GetCreateTime return create time
	GetCreateTime() int64
	// SetCreateTime set create time
	SetCreateTime(ct int64)
}

Entity define the list entity interface

type IDScore

type IDScore [2]int64

IDScore [0]target id,[1]score id

Jump to

Keyboard shortcuts

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