{"id":45079,"library":"hapi-redis","title":"hapi-redis","description":"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.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/sandfox/node-hapi-redis","tags":["javascript","hapi","redis","plugin"],"install":[{"cmd":"npm install hapi-redis","lang":"bash","label":"npm"},{"cmd":"yarn add hapi-redis","lang":"bash","label":"yarn"},{"cmd":"pnpm add hapi-redis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"manages redis connections","package":"basic-redis-factory","optional":false}],"imports":[{"note":"Package does not export ESM; use CommonJS require. hapi plugins are typically used with require().","wrong":"import HapiRedis from 'hapi-redis'","symbol":"hapi-redis","correct":"const HapiRedis = require('hapi-redis')"},{"note":"Access via server.plugins object after registration. The key is a string with hyphens, so bracket notation is required.","wrong":"server.plugins.hapi-redis.client","symbol":"client","correct":"server.plugins['hapi-redis'].client"},{"note":"The redis library is exposed on server.plugins, not request.plugins. Use request.server for route handlers.","wrong":"request.plugins['hapi-redis'].library","symbol":"library","correct":"request.server.plugins['hapi-redis'].library"}],"quickstart":{"code":"const Hapi = require('hapi');\n\nconst server = new Hapi.Server();\nserver.connection({ port: 3000 });\n\nconst options = {\n  connection: {\n    host: process.env.REDIS_HOST || '127.0.0.1',\n    port: process.env.REDIS_PORT || 6379\n  }\n};\n\nserver.register({\n  register: require('hapi-redis'),\n  options: options\n}, (err) => {\n  if (err) throw err;\n\n  server.route({\n    method: 'GET',\n    path: '/',\n    handler: (request, reply) => {\n      const client = request.server.plugins['hapi-redis'].client;\n      client.get('key', (err, value) => {\n        if (err) return reply(err);\n        reply(value);\n      });\n    }\n  });\n\n  server.start((err) => {\n    if (err) throw err;\n    console.log('Server running at:', server.info.uri);\n  });\n});\n","lang":"javascript","description":"Registers hapi-redis plugin with custom host/port, defines a route that uses the shared Redis client."},"warnings":[{"fix":"Wrap options in { connection: { host: ..., port: ..., opts: ... } }","message":"In version 6.0.0, the options object changed signature. Previously supported 'url', but now requires 'connection' object with nested properties.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade to hapi-redis@3.0.1 or later","message":"Version 3.0.0 introduced .net client leaking on multiple plugin registrations. Must upgrade to latest 3.x.x","severity":"breaking","affected_versions":"3.0.0"},{"fix":"Pass desired redis module via { redisLibrary: require('redis') } in options","message":"The '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.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Wrap server.register in try/catch or handle error callback.","message":"Connection errors during plugin registration will cause server startup to fail. Ensure Redis is reachable before starting server.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Define routes inside the server.register callback.","message":"Accessing client before plugin registration completes yields undefined. Route handlers must be defined after registration callback fires.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'6.0.0':21 'accept':39 'across':12 'addit':63 'allow':33 'automat':53 'configur':64 'connect':11,27,54 'current':17 'custom':41 'design':22 'differenti':45 'entir':14 'handl':55 'hapi':2,4,15,24,49,66 'hapi-redi':1 'hiredi':60 'integr':47 'javascript':65 'key':44 'librari':43 'multipl':34 'object':32 'option':38 'parser':61 'plugin':5,35,51,68 'provid':7 'redi':3,10,42,67 'registr':36 'server':16 'share':9 'simpl':46 'stabl':18 'string':30 'support':26,57 'system':52 'url':29 'v8.x.x':25 'version':19 'via':28 'without':62","created_at":"2026-06-07T12:53:16.530859+00:00","updated_at":"2026-06-07T12:53:16.530859+00:00","problems":[{"fix":"Access client inside server.register callback: request.server.plugins['hapi-redis'].client","cause":"Plugins not registered or accessed before registration completes.","error":"TypeError: Cannot read property 'client' of undefined"},{"fix":"Start Redis server or provide correct host/port in options.","cause":"Redis server not running or connection options incorrect.","error":"Error: connect ECONNREFUSED 127.0.0.1:6379"},{"fix":"Upgrade to hapi-redis@3.x.x which supports multiple registrations, or avoid double registration.","cause":"Trying to register plugin multiple times without allowing multiple registrations (requires v3+).","error":"Unhandled rejection: Error: The plugin 'hapi-redis' is already registered"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sandfox/node-hapi-redis#readme","github":"git://github.com/sandfox/node-hapi-redis","docs":null,"changelog":null,"pypi":null,"npm":"hapi-redis","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}