npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-rank

v2.2.2

Published

Manage real-time leaderboards using Redis

Downloads

4,425

Readme

Features

  • Lightweight: minimal dependencies, only ioredis is required
  • Performance: guaranteed at most one trip to Redis on each function call*, taking advantage of ioredis's pipelining and Lua scripts
  • Drop-in replacement: use any existing sorted set as a leaderboard
  • Clear interface: Promise-based & provides TypeScript definitions
  • Periodic leaderboards: create recurring leaderboards: daily, weekly, monthly, etc or use a custom cycle
  • Combine leaderboards: create a matrix of leaderboards: update, filter and retrieve multiple entries in a single call
  • Export: export your leaderboards for long-term storage
  • Tested: 100% code coverage

Quick Start

⚙️ Install

⚠️ For ioredis <= 4.x use [email protected], for ioredis >= 5.x use the latest version.

$ npm install redis-rank ioredis

Redis 2.6.12 or newer is required. The package ioredis is a peer dependency and must be installed separately.

🔗 Import and connect

ES5

const Redis = require('ioredis');
const { Leaderboard, PeriodicLeaderboard, LeaderboardMatrix } = require('redis-rank');

ES6

import { Redis } from 'ioredis';
import { Leaderboard, PeriodicLeaderboard, LeaderboardMatrix } from 'redis-rank';

You will have to provide a ioredis connection. See here for more information.

const client = new Redis({
    host: "127.0.0.1",
    port: 6379
});

You are ready, now read one of the examples linked below!

Examples

API

Running tests

A Redis server in localhost without password is expected. You can create one easily with Docker like so:

docker run -p 6379:6379 -t -i --rm redis:latest

⚠️ Note: The database #15 will be flushed ⚠️

Run tests:

npm test

I tried with ioredis-mock but I experienced some issues with Lua scripts so we have to rely on a real Redis server (which I think is better anyway).

License

MIT. See LICENSE.