Go Leaderboard 一个redis支持的排行榜处理程序

网友投稿 596 2022-10-23

Go Leaderboard 一个redis支持的排行榜处理程序

Go Leaderboard 一个redis支持的排行榜处理程序

Go Leaderboard

A redis backed leaderboard handler written in go.

Installation

$ go get github.com/tehsis/leaderboard

Example

package main;import ( "fmt" "github.com/tehsis/leaderboard" redis "gopkg.in/redis.v5") func main() { client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", }) scores := leaderboard.NewRedisLeaderBoard("Space Invaders", client) scores.Set("Tehsis", 100) scores.Set("0xBunny", 10) scores.Set("Plaurino", 50) top2 := scores.GetTop(2) fmt.Println("THE BEST TWO PLAYERS!") for index, score := range top2 { fmt.Printf("%v - %v : %v\n", index+1, score.Username, score.Points) } currentUser := "0xBunny" currentUserScore, currentUserPosition := scores.Get(currentUser) fmt.Printf("User %v is in position %v with %v points\n", currentUser, currentUserScore, currentUserPosition)}

The previous snippet will produce the following output:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:synchronized已经不在臃肿了,放下对他的成见之初识轻量级锁
下一篇:maven如何使用slf4j输出日志到文件
相关文章

 发表评论

暂时没有评论,来抢沙发吧~