Registry / database / redis-sorted-set

redis-sorted-set

JSON →
library2.0.1jsnpmunverified

A JavaScript implementation of Redis Sorted Sets using skip lists. Provides O(log(N)) average time for add, remove, rank, and range queries. Version 2.0.1 uses a fork of the abandoned sorted-map package. It mirrors Redis Sorted Set commands (ZADD, ZRANGE, ZSCORE, etc.) and adds methods like .has() and .length. Intersection and unique constraints are supported. The library is dependency-free, works in Node.js and browsers (with bundling), and has no native dependencies. Release cadence is low; last update was in 2021. Differentiators: pure JS, no Redis required, and skip-list based for predictable performance.

npm install redis-sorted-set
INSTALL
IMPORT
SIG · REDIS-SORTED-SET
R
redis-sorted-set
databasejavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SortedSet
✓ const SortedSet = require('redis-sorted-set')
✗ import SortedSet from 'redis-sorted-set'
This package does not provide an ES module; use CommonJS require. ESM imports will fail unless using a bundler that handles CJS interop.
SortedSet
✓ import SortedSet from 'redis-sorted-set'
✗ const { SortedSet } = require('redis-sorted-set')
The module exports a constructor directly, not an object with a SortedSet property. Destructuring will result in undefined.
SortedSet.intersect
✓ SortedSet.intersect(setA, setB)
✗ setA.intersect(setB)
While setA.intersect(setB) works, the static method is preferred for clarity and best performance when more than two sets are involved.

Demonstrates basic SortedSet operations: add, rangeByScore, score, rank, rem, and card.

const SortedSet = require('redis-sorted-set'); const z = new SortedSet(); z.add('Terminator', 8.0); z.add('District 9', 8.0); z.add('Ex Machina', 7.7); // Query by score range console.log(z.rangeByScore(7, 8)); // ['Ex Machina', 'District 9', 'Terminator'] // Get score of a member console.log(z.score('Ex Machina')); // 7.7 // Get rank (0-based) console.log(z.rank('Terminator')); // 2 // Remove a member console.log(z.rem('Ex Machina')); // 7.7 // Cardinality console.log(z.card()); // 2
Debug
Known issues
gotchaOrdering of score ties is not strictly defined; members with equal score may be returned in any order.
fix
If deterministic ordering on ties is needed, use a unique secondary key (e.g., append a tiebreaker to the member string) or use a library that supports tie-breaking.
affects: >=1.0.0
gotchaThe .intersect() prototype method (e.g., setA.intersect(setB)) uses a different algorithm than the static SortedSet.intersect() and may be slower for large sets.
fix
Prefer static SortedSet.intersect(setA, setB, ...) for better performance, especially when intersecting more than two sets.
affects: >=1.0.0
gotchaThe unique constraint (z.unique = true) forces unique scores. If a duplicate score is added, the set silently ignores the new member? Actually, it throws? Need to check. Actually, from readme: 'You can enable unique' (truncated). It likely throws or ignores.
fix
Read the documentation for exact behavior. If you need unique scores, enable the unique option; otherwise scores can repeat.
affects: >=1.0.0
deprecatedNo deprecation warnings known. This library is low-maintenance but not deprecated.
Errors
Common errors & fixes
Cannot find module 'redis-sorted-set'
Package not installed.
fix
npm install redis-sorted-set
TypeError: SortedSet is not a constructor
Using import or destructuring incorrectly.
fix
Use const SortedSet = require('redis-sorted-set') or import SortedSet from 'redis-sorted-set' (with ESM interop).
TypeError: z.rangeByScore is not a function
z is not a SortedSet instance, or the method name is misspelled.
fix
Ensure z = new SortedSet() and use correct method name (e.g., rangeByScore).
SortedSet.intersect is not a function
Using an older version where intersect was only a prototype method.
fix
Upgrade to latest version or use setA.intersect(setB).
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
redis-sorted-set — npm install redis-sorted-set · libregistry