https://github.com/axiaoxin-com/zranking
mod: golang redis zset ranking
https://github.com/axiaoxin-com/zranking
rank zset
Last synced: about 1 month ago
JSON representation
mod: golang redis zset ranking
- Host: GitHub
- URL: https://github.com/axiaoxin-com/zranking
- Owner: axiaoxin-com
- License: mit
- Created: 2022-11-07T04:43:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-30T02:18:56.000Z (over 2 years ago)
- Last Synced: 2025-03-26T08:37:11.599Z (about 2 months ago)
- Topics: rank, zset
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zranking

使用 redis zset 实现的排行榜 golang 封装
## 实现原理
使用redis zset,得分相同时,按时间先后进行排序;
将zset score按十进制数拆分,score十进制数字总共固定为16位(超过16位的数会有浮点数精度导致进位的问题),
整数部分用于表示用户排序值val,小数部分表示排行活动结束时间戳(秒)与用户排序值更新时间戳(秒)的差值deltaTs,
小数部分的数字长度由deltaTs的数字长度确定,整数部分最大支持长度则为:16-len(deltaTs)。
比如活动时长为10天,总时间差为864000,长度为6,则deltaTs宽度为6,不够则在前面补0。## 安装使用
```
go get -u github.com/axiaoxin-com/zranking
```示例:[_example/main.go](./_example/main.go) 或参考 [zranking_test.go](./zranking_test.go)
## Star History
[](https://star-history.com/#axiaoxin-com/zranking&Date)