Registry / database / redis-index

redis-index

JSON →
library4.1.0jsnpmunverified

Index and query arbitrary JavaScript objects using Redis. Version 4.1.0 provides a simple API to index objects by fields and perform search queries with OR conditions, full-text search, sorting, paging, and compression. It supports callbacks and Promises, and offers schema-based indexing. Compared to RediSearch, redis-index is a lightweight library that works with standard Redis (no modules needed), but lacks advanced query features like aggregation and ranked search. Active maintenance on GitHub with regular releases.

npm install redis-index
INSTALL
IMPORT
SIG · REDIS-INDEX
R
redis-index
databasejavascriptv4.1.0
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.

RedisIndex
const { RedisIndex } = require('redis-index');
const RedisIndex = require('redis-index');
The package exports an object with constructor RedisIndex and static compression helpers. CommonJS require must destructure or use require('redis-index').RedisIndex.
createIndex
import { createIndex } from 'redis-index';
import createIndex from 'redis-index';
ESM named import; the package does not have a default export.
compression
const { compression } = require('redis-index');
compression is an object with built-in compressors like gzip.

Create a RedisIndex, add objects with a unique identifier, search with OR conditions, and retrieve results.

import { createIndex } from 'redis-index'; import { createClient } from 'redis'; const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); await client.connect(); const index = createIndex({ redis: client, key: 'items', index: 'item_id', schemaOnly: false }); await index.add({ item_id: 1, name: 'thing a', type: 100 }); await index.add({ item_id: 2, name: 'thing b', type: 100 }); await index.add({ item_id: 3, name: 'thing c', type: 200 }); const results = await index.search({ name: 'b' }).or({ item_id: 1 }).exec(); console.log(results); // [ { item_id: 1, name: 'thing a', type: 100 }, { item_id: 2, name: 'thing b', type: 100 } ] await client.quit();
Debug
Known issues
breakingIn version 4.0, the API changed from callback-style to Promise-based for methods like add() and exec().
fix
Use async/await or .then() instead of callbacks. For example: await index.add(obj); instead of index.add(obj, callback);
affects: >=4.0.0
breakingIn version 4.0, the library requires a Redis client instance passed as 'redis' in options instead of using default connection settings.
fix
Create a Redis client (e.g., from 'redis' package) and pass it as: createIndex({ redis: client, ... })
affects: >=4.0.0
deprecatedThe old constructor pattern RedisIndex() is deprecated; use createIndex(options) instead.
fix
Replace new RedisIndex({...}) with createIndex({...})
affects: >=4.0.0
gotchaCompression functions are synchronous and must implement encode/decode. The provided compression.gzip requires Node.js zlib module.
fix
Ensure encode and decode are synchronous and handle errors internally.
affects: *
gotchaThe 'index' option (object ID field) must uniquely identify each object; duplicate IDs will overwrite previous data.
fix
Use a unique key (like a database primary key) for the index field.
affects: *
Errors
Common errors & fixes
TypeError: createIndex is not a function
Importing the package incorrectly, e.g., default import instead of named import.
fix
Use import { createIndex } from 'redis-index'; or const { createIndex } = require('redis-index');
RedisIndex.createIndex is not a function
Attempting to call createIndex on the default export instead of the named export.
fix
Use require('redis-index').createIndex or destructure.
ERR wrong number of arguments for 'FT.SEARCH' command
Trying to use RediSearch commands directly; redis-index does not use RediSearch.
fix
Use redis-index's search() method instead of raw Redis commands.
Error: The 'fullText' option must be a function
Passing a non-function value for fullText option.
fix
Provide a function that returns a string for full-text indexing.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
redisrequiredRequired for all Redis operations
Agent activity
15 hits · last 30 days
node
12
Meta
1
Resources
redis-index — npm install redis-index · libregistry