redchart

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

README

ranking charts based on redis

Leaderboard

Leaderboard is a chart which sort elements by a given weight from high to low.

BubbleChart

BubbleChart is a chart which can only append or swap element(s).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BubbleChart

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

func GetBubbleChart

func GetBubbleChart(rcli redis.Client, name string, opts ...Option) BubbleChart

func (BubbleChart) Append

func (x BubbleChart) Append(
	ctx context.Context, entries []Entry, opts ...Option) (err error)

append entries to the end of chart

func (BubbleChart) GetById

func (x BubbleChart) GetById(
	ctx context.Context, ids []string, opts ...Option) (entries []Entry, err error)

func (BubbleChart) GetByRank

func (x BubbleChart) GetByRank(
	ctx context.Context, offset, count int32, opts ...Option) (entries []Entry, err error)

get entries by range

func (BubbleChart) RemoveById

func (x BubbleChart) RemoveById(
	ctx context.Context, ids []string, opts ...Option) (err error)

remove chart entry by id

func (BubbleChart) SetInfo

func (x BubbleChart) SetInfo(
	ctx context.Context, entries []Entry, opts ...Option) (err error)

set entry info

func (BubbleChart) SwapById

func (x BubbleChart) SwapById(
	ctx context.Context, id1, id2 string, opts ...Option) (err error)

swap 2 entries by id

func (BubbleChart) SwapByRank

func (x BubbleChart) SwapByRank(
	ctx context.Context, rank1, rank2 int32, opts ...Option) (err error)

swap 2 entries by rank

func (BubbleChart) Touch

func (x BubbleChart) Touch(ctx context.Context, opts ...Option) (err error)

Touch modify metadata over chart options

type Client

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

func New

func New(rcli redis.Client) Client

func (Client) GetBubbleChart

func (cli Client) GetBubbleChart(name string, opts ...Option) BubbleChart

func (Client) GetLeaderboard

func (cli Client) GetLeaderboard(name string, opts ...Option) Leaderboard

type E

type E = Entry

type Entry

type Entry struct {
	Rank  int32  `json:"rank" msgpack:"rank"`
	Id    string `json:"id" msgpack:"id"`
	Info  string `json:"info" msgpack:"info"`
	Score int64  `json:"score" msgpack:"score"`
}

Entry代表排行榜中的一条数据 Entry.Rank 从0开始的榜单排名 Entry.Id 对象ID Entry.Score 对象分数,排名依据 Entry.Info 对象的详细信息

func (Entry) String

func (e Entry) String() string

type Leaderboard

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

func GetLeaderboard

func GetLeaderboard(rcli redis.Client, name string, opts ...Option) Leaderboard

func (Leaderboard) GetById

func (x Leaderboard) GetById(
	ctx context.Context, ids []string, opts ...Option) (entries []Entry, err error)

func (Leaderboard) GetByRank

func (x Leaderboard) GetByRank(
	ctx context.Context, offset, count int32, opts ...Option) (entries []Entry, err error)

get entries by range

func (Leaderboard) RandByScore

func (x Leaderboard) RandByScore(
	ctx context.Context, args []RandByScoreArg, opts ...Option) (entries []Entry, err error)

get entries randomly by score

func (Leaderboard) RemoveById

func (x Leaderboard) RemoveById(
	ctx context.Context, ids []string, opts ...Option) (err error)

remove chart entry by id

func (Leaderboard) Set

func (x Leaderboard) Set(
	ctx context.Context, entries []Entry, opts ...Option) (_ []Entry, err error)

func (Leaderboard) SetInfo

func (x Leaderboard) SetInfo(
	ctx context.Context, entries []Entry, opts ...Option) (err error)

set entry info

func (Leaderboard) SetOne

func (x Leaderboard) SetOne(
	ctx context.Context, entry Entry, opts ...Option) (_ Entry, err error)

func (Leaderboard) Touch

func (x Leaderboard) Touch(ctx context.Context, opts ...Option) (err error)

Touch modify metadata over chart options

type Option

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

func WithCapacity

func WithCapacity(capacity int32) Option

func WithConstructFrom

func WithConstructFrom(name string) Option

func WithExpire

func WithExpire(d time.Duration) Option

func WithExpireAt

func WithExpireAt(t time.Time) Option

func WithNoInfo

func WithNoInfo(v bool) Option

func WithNoTrim

func WithNoTrim(v bool) Option

func WithPersist

func WithPersist(v bool) Option

func WithSetIncrBy

func WithSetIncrBy(v bool) Option

func WithSetOnlyAdd

func WithSetOnlyAdd(v bool) Option

func WithSetOnlyUpdate

func WithSetOnlyUpdate(v bool) Option

type Options

type Options struct {
	// 榜单的最大容量
	Capacity int32 `msgpack:"capacity,omitempty"`
	// 默认情况下,在达到榜单最大容量时将淘汰末位对象
	// NoTrim修改此行为为超过容量报错
	NoTrim bool `msgpack:"no_trim,omitempty"`
	// 当请求榜单不存在时从指定榜单复制,可以用来制造榜单快照
	ConstructFrom string `msgpack:"construct_from,omitempty"`
	// 在进行榜单复制时忽略Info数据,只保留排名数据
	// 还有另外一个作用,查询榜单时指定该参数将不返回Info
	NoInfo bool `msgpack:"no_info,omitempty"`
	// 设置过期时间,以秒为单位的Unix时间戳
	// 参数为空则不对过期时间进行修改
	ExpireAt string `msgpack:"expire_at,omitempty"`
	// 设置过期时间,从当前时间算起的秒数
	// 如果和ExpireAt同时设置,该参数将被忽略
	// 参数为空则不对过期时间进行修改
	Expire string `msgpack:"expire,omitempty"`
	// 设置为不过期,不过期是默认行为
	// 该参数只为清除Expire(At)设置的超时时间
	Persist bool `msgpack:"persist,omitempty"`
	// 只对Set生效的参数
	Set SetOptions `msgpack:"set,omitempty"`
}

type RandByScoreArg

type RandByScoreArg struct {
	Min   int64 `json:"min" msgpack:"min"`
	Max   int64 `json:"max" msgpack:"max"`
	Count int   `json:"count" msgpack:"count"`
}

type SetOptions

type SetOptions struct {
	// 只增加新的元素,已有元素不进行更新,OnlyAdd和OnlyUpdate不能同时为true
	// ZADD.NX
	OnlyAdd bool `msgpack:"only_add,omitempty"`
	// 只更新已有元素,不新增元素,OnlyAdd和OnlyUpdate不能同时为true
	// ZADD.XX
	OnlyUpdate bool `msgpack:"only_update,omitempty"`
	// 对分数进行增加而不是替换
	// ZADD.INCR
	IncrBy bool `msgpack:"incr_by,omitempty"`
}

只对Set方法生效的参数

Jump to

Keyboard shortcuts

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