Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pager/hapi-redis

Package Overview
Dependencies
Maintainers
9
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pager/hapi-redis

A redis hapi plugin

  • 2.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

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 methodPromisified method
setsetAsync
getgetAsync
flushallflushallAsync
quitquitAsync
keyskeysAsync
ttlttlAsync

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.

Keywords

FAQs

Package last updated on 09 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc