UNPKG

realtime-leaderboard

Version:
96 lines 3.38 kB
export declare enum _LeaderboardUpdateOptions { updateOnly = "XX", createOnly = "NX", createAndUpdateIfLess = "LT", createAndUpdateIfGrater = "GT", createAndIncrement = "INCR" } export declare enum LeaderboardUpdateOptions { updateOnly = "updateOnly", createOnly = "createOnly", createAndUpdateIfLess = "createAndUpdateIfLess", createAndUpdateIfGrater = "createAndUpdateIfGrater", createAndIncrement = "createAndIncrement" } export declare type LeaderboardUpdateOptionsType = "updateOnly" | "createOnly" | "createAndUpdateIfLess" | "createAndUpdateIfGrater" | "createAndIncrement"; export declare type LeaderboardOptions = { update: LeaderboardUpdateOptionsType; }; /** * Leaderboard Class */ export declare class Leaderboard { leaderboardId: string; private opts; private client; clientType: import("./CustomRedisClient").RedisClientType; /** * Leaderboard class constructor * * @param redisClient - redisClient >>> Supports * * Redis {@link https://www.npmjs.com/package/redis} * * ioRedis {@link https://www.npmjs.com/package/ioredis} * * @param leaderboardId - Leaderboard Identifier * @param opts - Leaderboard Options */ constructor(redisClient: any, leaderboardId: string, opts: LeaderboardOptions); private static getUpdateOption; resetLeaderboard(): Promise<any>; getNoOfUsers(): Promise<any>; /** * Create User in Leaderboard * * @param userId - Unique User Identifier (ex: userId, username, email) * @param score - User's Score/Point */ createUser(userId: string | number, score: number): Promise<0 | 1>; /** * Update/Upsert User Record. According to LeaderboardUpdateOption selection. * * "updateOnly" : Never allows you to create new records if user doesn't exist. * * "createOnly" : Never allows you to update any user score. * * "createAndUpdateIfLess" : If user not exist, creates records, otherwise updates if new score * is less than current one. * * "createAndUpdateIfGrater" : If user not exist, creates records, otherwise updates if new score * is greater than current one. * * "createAndIncrement" : If user not exist, creates records, otherwise adds up new score. * * @param userId - Unique User Identifier (ex: userId, username, email) * @param score - User's Score/Point */ updateUser(userId: string | number, score: number): Promise<any>; /** * Get User's Score by user identifier. * * @param userId - Unique User Identifier (ex: userId, username, email) */ getScore(userId: number | string): Promise<number | null>; /** * Get User's Rank by user identifier. Min: 1 * * @param userId - Unique User Identifier (ex: userId, username, email) */ getRank(userId: number | string): Promise<number | null>; /** * It returns users between startRank [included] & endRank [included] * * Default: Returns whole leaderboard. * * @param startRank - Min: 1 * @param endRank */ getListBetween(startRank?: number, endRank?: number): Promise<{ userId: number | string; score: number; rank: number; }[]>; private static zrevrangeResponse; } //# sourceMappingURL=Leaderboard.d.ts.map