leaderboard

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the leaderboard manager object. Capable of managing multiple leaderboards.

func NewClient

func NewClient(host string, port int, password string, db int, connectionTimeout int) (*Client, error)

NewClient creates a leaderboard prepared to receive commands (host, port, password, db and connectionTimeout are used for connecting to Redis)

func NewClientWithRedis

func NewClientWithRedis(cli *tfgredis.Client) *Client

NewClientWithRedis creates a leaderboard using an already connected tfg Redis

func (*Client) GetAroundMe

func (c *Client) GetAroundMe(ctx context.Context, leaderboardID string, pageSize int, memberID string, order string,
	getLastIfNotFound bool) ([]*Member, error)

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

func (*Client) GetAroundScore

func (c *Client) GetAroundScore(ctx context.Context, leaderboardID string, pageSize int, score int64, order string) ([]*Member, error)

GetAroundScore returns a page of results centered in the score provided

func (*Client) GetLeaders

func (c *Client) GetLeaders(ctx context.Context, leaderboardID string, pageSize, page int, order string) ([]*Member, error)

GetLeaders returns a page of members with rank and score

func (*Client) GetMember

func (c *Client) GetMember(ctx context.Context, leaderboardID string, memberID string, order string, includeTTL bool) (*Member, error)

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

func (*Client) GetMembers

func (c *Client) GetMembers(ctx context.Context, leaderboardID string, memberIDs []string, order string, includeTTL bool) ([]*Member, error)

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

func (*Client) GetMembersByRange

func (c *Client) GetMembersByRange(ctx context.Context, leaderboard string, startOffset int, endOffset int, order string) ([]*Member, error)

GetMembersByRange for a given leaderboard

func (*Client) GetRank

func (c *Client) GetRank(ctx context.Context, leaderboardID string, memberID string, order string) (int, error)

GetRank returns the rank of the member with the given ID

func (*Client) GetTopPercentage

func (c *Client) GetTopPercentage(ctx context.Context, leaderboardID string, pageSize, amount, maxMembers int, order string) ([]*Member, error)

GetTopPercentage of members in the leaderboard.

func (*Client) IncrementMemberScore

func (c *Client) IncrementMemberScore(ctx context.Context, leaderboardID string, memberID string, increment int,
	scoreTTL string) (*Member, error)

IncrementMemberScore sets the score to the member with the given ID

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (string, error)

func (*Client) RemoveLeaderboard

func (c *Client) RemoveLeaderboard(ctx context.Context, leaderboardID string) error

RemoveLeaderboard removes a leaderboard from redis

func (*Client) RemoveMember

func (c *Client) RemoveMember(ctx context.Context, leaderboardID string, memberID string) error

RemoveMember removes the member with the given publicID from the leaderboard

func (*Client) RemoveMembers

func (c *Client) RemoveMembers(ctx context.Context, leaderboardID string, memberIDs []interface{}) error

RemoveMembers removes the members with the given publicIDs from the leaderboard

func (*Client) SetMemberScore

func (c *Client) SetMemberScore(ctx context.Context, leaderboardID string, memberID string, score int64, prevRank bool, scoreTTL string) (*Member, error)

SetMemberScore sets the score to the member with the given ID

func (*Client) SetMembersScore

func (c *Client) SetMembersScore(ctx context.Context, leaderboardID string, members Members, prevRank bool,
	scoreTTL string) error

SetMembersScore sets the scores of the members with the given IDs

func (*Client) TotalMembers

func (c *Client) TotalMembers(ctx context.Context, leaderboardID string) (int, error)

TotalMembers returns the total number of members in a given leaderboard

func (*Client) TotalPages

func (c *Client) TotalPages(ctx context.Context, leaderboardID string, pageSize int) (int, error)

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

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

Jump to

Keyboard shortcuts

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