Powerful Scalable real-time Leaderboards using Redis for million+ users.
- 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
$ npm install realtime-leaderboard
$ npm install redis
or $ npm install ioredis
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});
const { Leaderboard } = require("realtime-leaderboard");
const lb = new Leaderboard(redisClient, "leaderboardId", { update: "createAndUpdateIfGrater" });
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