leaderboard

package
v7.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leaderboard

type Leaderboard struct {
	Logger      zap.Logger
	RedisClient interfaces.RedisClient
	PublicID    string
	PageSize    int
}

Leaderboard identifies a leaderboard with given redis client

func NewLeaderboard

func NewLeaderboard(redisClient interfaces.RedisClient, publicID string, pageSize int, logger zap.Logger) *Leaderboard

NewLeaderboard creates a new Leaderboard with given settings, ID and pageSize

func (*Leaderboard) AddToLeaderboardSet

func (lb *Leaderboard) AddToLeaderboardSet(members Members, prevRank bool, scoreTTL string) error

AddToLeaderboardSet adds a score to a leaderboard set respecting expiration

func (*Leaderboard) GetAroundMe

func (lb *Leaderboard) GetAroundMe(memberID string, order string, getLastIfNotFound bool) ([]*Member, error)

GetAroundMe returns a page of results centered in the member with the given ID

func (*Leaderboard) GetAroundScore

func (lb *Leaderboard) GetAroundScore(score int64, order string) ([]*Member, error)

GetAroundScore returns a page of results centered in the score provided

func (*Leaderboard) GetLeaders

func (lb *Leaderboard) GetLeaders(page int, order string) ([]*Member, error)

GetLeaders returns a page of members with rank and score

func (*Leaderboard) GetMember

func (lb *Leaderboard) GetMember(memberID string, order string, includeTTL bool) (*Member, error)

GetMember returns the score and the rank of the member with the given ID

func (*Leaderboard) GetMembers

func (lb *Leaderboard) GetMembers(memberIDs []string, order string, includeTTL bool) ([]*Member, error)

GetMembers returns the score and the rank of the members with the given IDs

func (*Leaderboard) GetRank

func (lb *Leaderboard) GetRank(memberID string, order string) (int, error)

GetRank returns the rank of the member with the given ID

func (*Leaderboard) GetTopPercentage

func (lb *Leaderboard) GetTopPercentage(amount, maxMembers int, order string) ([]*Member, error)

GetTopPercentage of members in the leaderboard.

func (*Leaderboard) IncrementMemberScore

func (lb *Leaderboard) IncrementMemberScore(memberID string, increment int, scoreTTL string) (*Member, error)

IncrementMemberScore sets the score to the member with the given ID

func (*Leaderboard) RemoveLeaderboard

func (lb *Leaderboard) RemoveLeaderboard() error

RemoveLeaderboard removes a leaderboard from redis

func (*Leaderboard) RemoveMember

func (lb *Leaderboard) RemoveMember(memberID string) error

RemoveMember removes the member with the given publicID from the leaderboard

func (*Leaderboard) RemoveMembers

func (lb *Leaderboard) RemoveMembers(memberIDs []interface{}) error

RemoveMembers removes the members with the given publicIDs from the leaderboard

func (*Leaderboard) SetMemberScore

func (lb *Leaderboard) SetMemberScore(memberID string, score int64, prevRank bool, scoreTTL string) (*Member, error)

SetMemberScore sets the score to the member with the given ID

func (*Leaderboard) SetMembersScore

func (lb *Leaderboard) SetMembersScore(members Members, prevRank bool, scoreTTL string) error

SetMembersScore sets the scores of the members with the given IDs

func (*Leaderboard) TotalMembers

func (lb *Leaderboard) TotalMembers() (int, error)

TotalMembers returns the total number of members in a given leaderboard

func (*Leaderboard) TotalPages

func (lb *Leaderboard) TotalPages() (int, error)

TotalPages returns the number of pages of the leaderboard

type Member

type Member struct {
	PublicID     string `json:"publicID"`
	Score        int64  `json:"score"`
	Rank         int    `json:"rank"`
	PreviousRank int    `json:"previousRank"`
	ExpireAt     int    `json:"expireAt"`
}

Member maps an member identified by their publicID to their score and rank

func GetMembersByRange

func GetMembersByRange(redisClient interfaces.RedisClient, leaderboard string, startOffset int, endOffset int, order string, l zap.Logger) ([]*Member, error)

GetMembersByRange for a given leaderboard

type MemberNotFoundError

type MemberNotFoundError struct {
	LeaderboardID string
	MemberID      string
}

MemberNotFoundError indicates member was not found in Redis

func NewMemberNotFound

func NewMemberNotFound(leaderboardID, memberID string) *MemberNotFoundError

NewMemberNotFound returns a new error for member not found

func (*MemberNotFoundError) Error

func (e *MemberNotFoundError) Error() string

type Members

type Members []*Member

Members are a list of member

func (Members) Len

func (slice Members) Len() int

func (Members) Less

func (slice Members) Less(i, j int) bool

func (Members) Swap

func (slice Members) Swap(i, j int)

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

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