@pager/hapi-redis

2.1.7 • Public • Published

hapi-redis

A node-redis hapi plugin

CircleCI

Installation

npm install --save @pager/hapi-redis

Quick start

This pretty much works as a regular node-redis client, with the addition of providing an easily accessible instance via the server.app common namespace.

Examples

const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ host: 'localhost' });

const options = {
    // node-redis config options - http://redis.js.org/#api-rediscreateclient
};

// Register the plugin
server.register({
    register: require('@pager/hapi-redis'),
    options: options
}, (err) => {

    if (err) {
        console.error(err);
    } 
    else {
        server.start(() => {

            console.info(`Server started at ${server.info.uri}`);
        });
    }
});

// Declare a route that uses it
server.route({
    method: 'GET',
    path: '/stats',
    handler: usersHandler
});

usersHandler (request, reply) => {

    // Access the redis instance
    const client = request.redis;
    client.hgetall('users', (err, obj) => {
    
        if (err) {
            throw err
        }

        return reply({ result: obj });
    });
};

server.start(() => {
    console.log(`Server started at ${server.info.uri}`);
});

Async support

You could use next promisified methods, e.g.:

const res = await getAsync(key);
Original method Promisified method
set setAsync
get getAsync
flushall flushallAsync
quit quitAsync
keys keysAsync
ttl ttlAsync

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Versions

  • Use 1.x.x for hapi@16
  • Use 2.x.x for hapi@17 or later

Acknowledgements

This module borrows heavily from hapi-ioredis.

Readme

Keywords

Package Sidebar

Install

npm i @pager/hapi-redis

Weekly Downloads

3

Version

2.1.7

License

MIT

Unpacked Size

5.96 kB

Total Files

5

Last publish

Collaborators

  • sean-mccoy-pager
  • anthonyhancock
  • marissa-pennington-pagerhealth
  • saidavuluri
  • sharmila8908
  • udayahugar
  • vristic
  • ebrcaninovic
  • guda-onlife
  • ahmed_vuk
  • josiah-pager-2024
  • howard-at-pager
  • guessed
  • lancehamiltonolh
  • duvanmonsa
  • edzebo
  • pager-juampi
  • marcie.price
  • levi-at-pager
  • lance_lyons
  • oxymor0n
  • roybay04
  • kuryaki
  • kevinchang-pager
  • lgenzelis
  • epsanchezma
  • nupiter
  • said-pager
  • juveria.shariff
  • jsalbert3
  • ewise_onlife
  • craig-parker-pager
  • jvelezpo
  • amalajose-onlife
  • jay-darren-miller
  • meerabjorn-onlife
  • richibbs
  • moui
  • matthew_moss
  • max-d-lucas
  • justin_pennington
  • cody-greene
  • adimoff
  • felipe.correa
  • catherinekimyj-pager
  • zacharyjuang
  • 18sheimanr
  • sapnamate
  • nachocasas
  • petermai-pager
  • brianseidl_pager
  • esteban.villa
  • joe.wacker.pager
  • batroukhhamza
  • calvinkosmatka
  • i-am-ian
  • timvallier-pager
  • ankita.banait
  • alena.b.pager
  • tjharke13
  • kyleherrmann
  • durenh
  • luciabrumnich.pager
  • chrisft25
  • juandara22
  • m4shu
  • juancabuhe
  • joan.semander
  • mariano-ramonda
  • fauricio-pager
  • divyasehgal
  • mark.ferris
  • dmsq22
  • exequiel-sanoner
  • juan.lacoste.pager
  • jiggyjigsj
  • ijuani
  • jsanmi
  • aftab-alam-khan
  • peter-vizi-pager
  • ramanvas
  • circle-pager
  • sa-pagerinc-automation
  • fcue
  • shankyjs
  • ryshah1207
  • gh0stl1m-p
  • blaine-pager
  • jmelero.pager