npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hapi-redis

v6.0.0

Published

redis client plugin for hapi

Downloads

167

Readme

Build Status Dependencies Status DevDependencies Status

Hapi-Redis

This is a plugin to share a common redis connection across the whole Hapi server.

This version is intended for use with hapi v8.x.x

If you are looking for a version that works with hapi v7.x.x then please use version 1.x.x

As of 3.x.x it is now possible to register this plugin multiple times

As of 4.x.x it is now possible to supply a connection string as the option

~~As of 4.x.x redis is now a peer dependency (0.12.x) to allow users more freedom with redis versions~~

As of 5.x.x we've scrapped redis as a peer deps

With 6.x.x the options object has changed it's signature

Registering the plugin

Options:

  • redisLibrary: passing in a redis module to override the one bundled with this module. optional.
  • connection: an object or string that is passed through to basic-redis-factory as the 2nd argument. The relevant part of the docs are reproduced here for ease of reference:

connection can either be a url connection string (i.e redis://user:[email protected]:6379) or an object.

if connection is an object then the factory will look for the following keys on the object and fallback to defaults for any missing values (host: 127.0.01, port: 6379, no authentication).

  • url : a url connection string.
  • host: the host to connect to.
  • port: the port to connect to.
  • password: the password to authenticate with, if not supplied then no auth will applied.
  • opts: an options object as expected by redis.createClient.

If opts.url is supplied then opts.host, opts.port, and opts.password keys will be ignored.

If you wish to use the hiredis parser then just:

npm install -save hiredis

and this module will automatically use it (unless you override that with the parser option).

The registration of this plugin will only complete on either succesful connection to the redis instance or an error.

Using the plugin

Two objects are exposed by this plugin :

  • client : a redis client connection object that is connected to the redis instance
  • library: the redis module used by this module

Example

var Hapi = require("hapi");

var myPluginOpts = {
    connection: {
        "host": "localhost"
        "opts": {
            "parser": "javascript"
        }
    }
};

var server = new Hapi.Server(8080);

server.pack.register({
    register: require('hapi-redis'),
    options: myPluginOpts
}, function () {

});

server.route( {
    "method"  : "GET",
    "path"    : "/stats",
    "handler" : usersHandler
});

function usersHandler(request, reply) {
    var redisClient = request.server.plugins['hapi-redis'].client;

    //Do something with thr redis client
    // reply(result);
};

server.start(function() {
    console.log("Server started at " + server.info.uri);
});