Hapi's redis plugin

Usage no npm install needed!

<script type="module">
  import hapiHiredis from 'https://cdn.skypack.dev/hapi-hiredis';



Hapi (^8.0) plugin for redis with hiredis parser.

Why use this instead of simple hapi-redis?

  • hiredis parser is way faster than the plain javascript parser that comes by default with the node redis module.
  • Support for URLs. At least for me that's a major point, since I store all the data for connections in a simple URL string.


npm install --save hiredis hapi-hiredis

Register plugin

You can pass as options either an URL (all are optionals, defaults to: no password, 127.0.01 and 6379) or host and port. Obviously passing an URL is way more convenient.

var Hapi = require('hapi');
var server = new Hapi.Server();

  register: require('hapi-hiredis'),
  opts: { url: 'redis://:password@domain.tld:port' }
}, function (err) {
  if (err) console.error(err);

Use plugin

The object returned by redis.createClient is exposed on server.plugins['hapi-hiredis'].client and binded to the context on routes and extensions as this.redis.

  method: 'GET',
  path: '/hashes',
  handler: function (request, reply) {
    var redis = request.server.plugins['hapi-hiredis'].client;
    redis.hgetall('hashes', function (err, obj) {
}, {
  method: 'GET',
  path: '/session',
  handler: function (request, reply) {
    var redis = this.redis;
    redis.get('session', function (err, obj) {

If for any reason you need to use the redis library, then you can use it from server.plugins['hapi-hiredis'].library.


Licensed under the terms of the ISC. A copy of the license can be found in the file LICENSE.

© 2015, Jose-Luis Rivas <me@ghostbar.co>