Registry / database / hapi-redis

hapi-redis

JSON →
library6.0.0jsnpmunverified

Hapi plugin that provides a shared Redis connection across the entire Hapi server. Current stable version is 6.0.0, designed for hapi v8.x.x. Supports connection via URL string or object, allows multiple plugin registrations, and optionally accepts a custom redis library. Key differentiators: simple integration with hapi's plugin system, automatic connection handling, and support for the `hiredis` parser without additional configuration.

npm install hapi-redis
INSTALL
IMPORT
SIG · HAPI-REDIS
H
hapi-redis
databasejavascriptv6.0.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.

hapi-redis
const HapiRedis = require('hapi-redis')
import HapiRedis from 'hapi-redis'
Package does not export ESM; use CommonJS require. hapi plugins are typically used with require().
client
server.plugins['hapi-redis'].client
server.plugins.hapi-redis.client
Access via server.plugins object after registration. The key is a string with hyphens, so bracket notation is required.
library
request.server.plugins['hapi-redis'].library
request.plugins['hapi-redis'].library
The redis library is exposed on server.plugins, not request.plugins. Use request.server for route handlers.

Registers hapi-redis plugin with custom host/port, defines a route that uses the shared Redis client.

const Hapi = require('hapi'); const server = new Hapi.Server(); server.connection({ port: 3000 }); const options = { connection: { host: process.env.REDIS_HOST || '127.0.0.1', port: process.env.REDIS_PORT || 6379 } }; server.register({ register: require('hapi-redis'), options: options }, (err) => { if (err) throw err; server.route({ method: 'GET', path: '/', handler: (request, reply) => { const client = request.server.plugins['hapi-redis'].client; client.get('key', (err, value) => { if (err) return reply(err); reply(value); }); } }); server.start((err) => { if (err) throw err; console.log('Server running at:', server.info.uri); }); });
Debug
Known issues
breakingIn version 6.0.0, the options object changed signature. Previously supported 'url', but now requires 'connection' object with nested properties.
fix
Wrap options in { connection: { host: ..., port: ..., opts: ... } }
affects: >=6.0.0
breakingVersion 3.0.0 introduced .net client leaking on multiple plugin registrations. Must upgrade to latest 3.x.x
fix
Upgrade to hapi-redis@3.0.1 or later
affects: 3.0.0
deprecatedThe 'redis' peer dependency was removed in version 5.x.x. If you relied on custom redis version, you must now pass it via 'redisLibrary' option.
fix
Pass desired redis module via { redisLibrary: require('redis') } in options
affects: >=5.0.0
gotchaConnection errors during plugin registration will cause server startup to fail. Ensure Redis is reachable before starting server.
fix
Wrap server.register in try/catch or handle error callback.
affects: >=0.0.0
gotchaAccessing client before plugin registration completes yields undefined. Route handlers must be defined after registration callback fires.
fix
Define routes inside the server.register callback.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'client' of undefined
Plugins not registered or accessed before registration completes.
fix
Access client inside server.register callback: request.server.plugins['hapi-redis'].client
Error: connect ECONNREFUSED 127.0.0.1:6379
Redis server not running or connection options incorrect.
fix
Start Redis server or provide correct host/port in options.
Unhandled rejection: Error: The plugin 'hapi-redis' is already registered
Trying to register plugin multiple times without allowing multiple registrations (requires v3+).
fix
Upgrade to hapi-redis@3.x.x which supports multiple registrations, or avoid double registration.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
basic-redis-factoryrequiredmanages redis connections
Agent activity
8 hits · last 30 days
node
8
Resources