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.fixIf 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.fixPrefer 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.fixRead 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.
fixnpm install redis-sorted-set
TypeError: SortedSet is not a constructor
Using import or destructuring incorrectly.
fixUse 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.
fixEnsure 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.
fixUpgrade to latest version or use setA.intersect(setB).
Audit
Dependencies
No dependency data recorded yet.