Registry / database / redis-json

redis-json

JSON →
library6.0.3jsnpmunverified

A library that stores JSON objects in Redis hashes without losing type information, using a flatten/unflatten approach. Current stable version is 6.0.3, with active development. It handles nested objects, arrays, and custom types via stringifier/parser options. Compared to directly storing JSON strings, it allows partial updates and field-level retrieval. Requires ioredis as a peer dependency. Ships TypeScript definitions.

npm install redis-json
INSTALL
IMPORT
SIG · REDIS-JSON
R
redis-json
databasejavascriptv6.0.3
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.

JSONCache
✓ import JSONCache from 'redis-json'
✗ import { JSONCache } from 'redis-json'
Default export is the class; named import fails in both ESM and CJS.
JSONCache
✓ const JSONCache = require('redis-json')
✗ const { JSONCache } = require('redis-json')
CJS require returns the default export directly.

Shows basic instantiation with ioredis, set/get operations, and clearing all keys.

import Redis from 'ioredis'; import JSONCache from 'redis-json'; const redis = new Redis(); const cache = new JSONCache(redis, { prefix: 'jc:' }); async function run() { const obj = { name: 'test', count: 42, tags: ['a', 'b'] }; await cache.set('123', obj); console.log(await cache.get('123')); await cache.clearAll(); } run();
Debug
Known issues
breakingIn v6.0.0, the behavior for array replacement changed: arrays cached in Redis are now replaced entirely when set is called with a new array.
fix
Review array handling logic in your app; previously arrays were merged.
affects: >=6.0.0
gotchaThe `clearAll()` method uses `scan` under the hood, which may cause high CPU usage on large datasets.
fix
Avoid calling `clearAll()` frequently; consider alternative TTL-based cleanup.
affects: >=1.0.0
gotchaTransactions are only supported for `set`, `rewrite`, `del`, and `incr` methods. Using `get` or `clearAll` inside a transaction will throw an error.
fix
Do not wrap `get` or `clearAll` in a multi/exec block; use them separately.
affects: >=1.0.0
deprecatedThe `clearAll` method is deprecated since v6.0.0 in favor of using Redis TTL or explicit key deletion.
fix
Replace `clearAll()` with a custom cleanup using Redis `scan` and `del`, or set TTL on keys.
affects: >=6.0.0
breakingBreaking change in v6: the `stringifier` and `parser` options now require functions that return string/object, not just serialize/deserialize.
fix
Update custom stringifiers/parsers to return appropriate types (string for stringifier, value for parser).
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: redis.hmset is not a function
The redis client instance is not ioredis; the library assumes ioredis API.
fix
Use an ioredis client instead of node-redis or other clients.
Error: get() does not support transactions
Calling get inside a multi() transaction.
fix
Use get outside transaction block.
Upgrade
Version history
6.0.3latest on npm
Audit
Dependencies
ioredisrequiredRedis client used for all operations
Agent activity
10 hits · last 30 days
node
8
Resources
redis-json — npm install redis-json · libregistry