Registry / database / predis

predis

JSON →
library1.1.4jsnpmunverified

Predis is a lightweight wrapper around the node-redis (node_redis) library that converts callback-based Redis commands to return Promises instead, simplifying asynchronous code with .then() and .catch(). Version 1.1.4 is the latest stable release; the package has not been updated since 2019 and relies on the older node_redis v0.x. It requires Node >=8. It is a minimal layer — it does not add TypeScript types, and does not support modern Redis features or the 'ioredis' alternative's cluster/sentinel support. For new projects, consider using ioredis or the native promise support in newer node-redis (v4+).

npm install predis
INSTALL
IMPORT
SIG · PREDIS
P
predis
databasejavascriptv1.1.4
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.

createClient
const predis = require('predis'); const client = predis.createClient();
import { createClient } from 'predis'; // No default export; must use require() or import *
Predis does not export a default module; it exports a namespace object with createClient. It is CommonJS-only, no ESM support.
client
client.get('foo').then(val => console.log(val));
client.get('foo', (err, val) => {}); // Predis returns a promise, not a callback
All Redis commands return Promises; callbacks are not supported directly.
multi()
const multi = client.multi(); multi.exec((err, replies) => {});
client.multi().exec().then(...); // multi exec does not return a promise
multi() and exec() follow the original callback style; promises are not returned for these methods.

Connects to Redis, sets and gets a key using promises, then disconnects.

const predis = require('predis'); const client = predis.createClient({ port: 6379, server: '127.0.0.1' }); client.set('greeting', 'Hello, Redis!') .then(() => client.get('greeting')) .then((value) => { console.log(value); // 'Hello, Redis!' }) .catch((err) => { console.error('Redis error:', err); }) .finally(() => client.quit());
Debug
Known issues
gotchamulti() and exec() do not return Promises; you must use callbacks.
fix
Wrap multi exec in a new Promise constructor: new Promise((resolve, reject) => { multi.exec((err, replies) => { if (err) reject(err); else resolve(replies); }); });
affects: >=1.0.0
deprecatedpredis depends on the deprecated node_redis v0.x ('redis' <4.0.0) which is no longer maintained.
fix
Migrate to a maintained Redis client like ioredis or the official redis v4 with built-in Promise support.
affects: >=1.0.0
breakingPredis is CommonJS-only. Using ES 'import' will fail with 'predis is not a function'.
fix
Use require('predis') or wrap with module.createRequire if using ES modules.
affects: >=1.0.0
gotchacreateClient expects 'server' and 'port' keys, not 'host' and 'port' as in node_redis.
fix
Use { server: '127.0.0.1', port: 6379 } instead of { host: '...' }.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: predis.createClient is not a function
Using ES module import on a CommonJS module that exports an object, not a function.
fix
Replace 'import predis from \"predis\"' with 'const predis = require(\"predis\")'.
TypeError: client.get(...).then is not a function
Using callback style instead of promised API; possibly using older node_redis directly.
fix
Ensure you are using the predis client (not the raw redis client) and do not pass a callback.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
No Redis server running or wrong connection options (server key misspelled or default host).
fix
Start redis-server or provide correct { server, port } options to createClient.
Warning: node_redis - The 'expire' option is deprecated and will be removed in a future version.
Using old node_redis v0.x configuration that is deprecated.
fix
Upgrade to a modern Redis client like ioredis.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
redisrequiredPredis wraps node_redis (npm package 'redis'). The 'redis' v0.x series is a peer dependency; predis does not work with redis v4+.
Agent activity
9 hits · last 30 days
node
8
Resources
packagepredis
predis — npm install predis · libregistry