realtime-leaderboard
v1.0.0
Published
Real-time powerful leaderboard with Redis
Downloads
11
Maintainers
Readme
Features
- Lightweight: no dependency requirements other than your redis client.
- Different Redis client support: This package works with redis or ioredis clients.
- Promise based
- TypeScript definitions
- Tested
- Powerful & Quick for over million users.
- Multiple real-time leaderboards
- Different Score Update Strategies: Different score update strategies can be set according to your app business logic for each leaderboard. More: Score Update Strategies
Installation
Install package(s)
$ npm install realtime-leaderboard
⚠️ Make sure you already have redis client, if you don't, redis or ioredis can be installed.
$ npm install redis
or $ npm install ioredis
Create || Get your redis client
This package requires your redis client.
redis client initilization: more
const redis = require("redis")
const redisClient = redis.createClient({host: "localhost",port: 6379})
ioredis client initilization more
const Redis = require('ioredis');
const redisClient = new Redis({ host: "localhost", port: 6379});
Create your Real-time Leaderboard
const { Leaderboard } = require("realtime-leaderboard");
const lb = new Leaderboard(redisClient, "leaderboardId", { update: "createAndUpdateIfGrater" });
Leaderboard Method Example
await lb.updateUser("user1", 15) // creates user1 since user not exist
await lb.createUser("user2", 32) // creates user2
await lb.updateUser("user1", 200) // update user1 since newScore is greater
const board = await lb.getListBetween(1, 7); // [{ user1 }, { user2 }]
const rank = await lb.getRank("user1") // 1
const score = await lb.getScore("user1") // 200
See more Score Update Strategies