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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@da440dil/rset

v0.0.0

Published

Redis sorted set with size limit within time frame

Readme

@da440dil/rset

CI Coverage Status

Redis sorted set with size limit within time frame.

Supports ioredis and node-redis.

Example push usage with ioredis:

import { setTimeout } from 'node:timers/promises';
import Redis from 'ioredis';
import { RSet } from '@da440dil/rset';

const client = new Redis();
// Create RSet with size limit of 3 values per key and value TTL of 500ms.
const rset = RSet.io(client, 3, 500);

async function main() {
	const user = '42';
	// Push token, pop if limit exceeded.
	for (let i = 0; i < 4; i++) {
		const v = `1${i}`;
		console.log(`PUSH: ${v} => ${await rset.push(user, v)}`);
		await setTimeout(100);
	}
	console.log(`GET: [${await rset.get(user)}]`);

	// Replace token if exists.
	for (let i = 0; i < 3; i++) {
		const [v1, v2] = [`1${i}`, `2${i}`];
		console.log(`REPLACE: ${v1} -> ${v2} => ${await rset.replace(user, v1, v2)}`);
		await setTimeout(100);
	}
	console.log(`GET: [${await rset.get(user)}]`);

	await setTimeout(100);
	console.log('TIMEOUT');
	console.log(`REPLACE: 13 -> 23 => ${await rset.replace(user, '13', '23')}`);
	console.log(`GET: [${await rset.get(user)}]`);
	console.log(`PUSH: 21 => ${await rset.push(user, '21')}`);
	console.log(`GET: [${await rset.get(user)}]`);
	// Output:
	// PUSH: 10 => 2
	// PUSH: 11 => 1
	// PUSH: 12 => 0
	// PUSH: 13 => -1
	// GET: [11,12,13]
	// REPLACE: 10 -> 20 => false
	// REPLACE: 11 -> 21 => true
	// REPLACE: 12 -> 22 => true
	// GET: [13,21,22]
	// TIMEOUT
	// REPLACE: 13 -> 23 => false
	// GET: [21,22]
	// PUSH: 21 => 1
	// GET: [22,21]
	await client.quit();
}

main().catch(console.error);
npm run file examples/push.ts

Example add usage with node-redis:

import { setTimeout } from 'node:timers/promises';
import { createClient } from 'redis';
import { RSet } from '@da440dil/rset';

const client = createClient();
// Create RSet with size limit of 3 values per key and value TTL of 500ms.
const rset = RSet.node(client, 3, 500);

async function main() {
	await client.connect();
	const user = '42';
	// Add token if limit not reached.
	for (let i = 0; i < 4; i++) {
		const v = `1${i}`;
		console.log(`ADD: ${v} => ${await rset.add(user, v)}`);
		await setTimeout(100);
	}
	console.log(`GET: [${await rset.get(user)}]`);

	// Replace token if exists.
	for (let i = 0; i < 2; i++) {
		const [v1, v2] = [`1${i}`, `2${i}`];
		console.log(`REPLACE: ${v1} -> ${v2} => ${await rset.replace(user, v1, v2)}`);
		await setTimeout(100);
	}
	console.log(`REPLACE: 13 -> 23 => ${await rset.replace(user, '13', '23')}`);
	console.log(`GET: [${await rset.get(user)}]`);

	await setTimeout(100);
	console.log('TIMEOUT');
	console.log(`REPLACE: 12 -> 22 => ${await rset.replace(user, '12', '22')}`);
	console.log(`GET: [${await rset.get(user)}]`);
	console.log(`ADD: 20 => ${await rset.add(user, '20')}`);
	console.log(`GET: [${await rset.get(user)}]`);
	// Output:
	// ADD: 10 => true
	// ADD: 11 => true
	// ADD: 12 => true
	// ADD: 13 => false
	// GET: [10,11,12]
	// REPLACE: 10 -> 20 => true
	// REPLACE: 11 -> 21 => true
	// REPLACE: 13 -> 23 => false
	// GET: [12,20,21]
	// TIMEOUT
	// REPLACE: 12 -> 22 => false
	// GET: [20,21]
	// ADD: 20 => true
	// GET: [21,20]
	await client.quit();
}

main().catch(console.error);
npm run file examples/add.ts