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.
reds
✓ import reds from 'reds';
✗ const reds = require('reds');
ESM default import works; reds is a CommonJS module but many bundlers support default import.
createSearch
✓ import { createSearch } from 'reds';
✗ const { createSearch } = require('reds');
Named export for createSearch; can be used in both ESM and CJS contexts.
Search
✓ import { Search } from 'reds';
✗ const Search = require('reds').Search;
Named export for the Search class; direct access to the constructor.
setClient
✓ import { setClient } from 'reds';
✗ const setClient = require('reds').setClient;
Named export to set a custom Redis client instance.
Shows full setup: Redis client creation, indexing multiple documents, and querying with both intersection (default) and union modes.
import reds from 'reds';
import redis from 'redis';
const client = redis.createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
reds.setClient(client);
const search = reds.createSearch('pets');
const strs = [];
strs.push('Tobi wants four dollars');
strs.push('Tobi only wants $4');
strs.push('Loki is really fat');
strs.push('Loki, Jane, and Tobi are ferrets');
strs.push('Manny is a cat');
strs.push('Luna is a cat');
strs.push('Mustachio is a cat');
// Index documents
strs.forEach((str, i) => {
search.index(str, i);
});
// Query with intersection (default)
search
.query('Tobi dollars')
.end((err, ids) => {
if (err) throw err;
console.log('Search results for "Tobi dollars":');
ids.forEach(id => console.log(' -', strs[id]));
});
// Query with union
search
.query('tobi dollars')
.type('or')
.end((err, ids) => {
if (err) throw err;
console.log('Search results for "tobi dollars" (union):');
ids.forEach(id => console.log(' -', strs[id]));
});
Errors
Common errors & fixes
TypeError: reds.createSearch is not a function
Using require() on ESM import or mismatched import style.
fixUse correct import: import reds from 'reds'; or const reds = require('reds').default; Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or connection parameters are wrong.
fixStart Redis server or set REDIS_URL environment variable to a valid Redis instance.
TypeError: search.query(...).end is not a function
Forgetting to call .query() returns a Query object; .type() and .end() are methods on that object.
fixChain correctly: search.query('text').end(callback); OR search.query('text').type('or').end(callback); Error: Cannot find module 'natural'
natural dependency not installed.
fixRun npm install natural (should be automatically installed with reds, but if missing, install explicitly).
Audit
Dependencies
redisrequiredRequired for Redis client operations; reds relies on a node_redis instance.
naturalrequiredProvides stemming and metaphone phonetic algorithms for text processing.