# @pager/hapi-redis

> A redis hapi plugin

Latest version **2.1.7** (published 2020-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pager/hapi-redis
pnpm add @pager/hapi-redis
yarn add @pager/hapi-redis
bun add @pager/hapi-redis
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.7 |
| Published | 2020-03-09 |
| First published | 2016-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.13 |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Gaston Festari |
| Maintainers | aorinevo, cilindrox, circle-pager, diegorbaquero, jenkins-pager, john.semander, ryanhallcs, sa-pagerinc-automation, timcosta-pager |
| Keywords | hapi, redis |

## Links

- npm: https://www.npmjs.com/package/@pager/hapi-redis
- Repository: https://github.com/pagerinc/hapi-redis
- Homepage: https://github.com/pagerinc/hapi-redis#readme
- Issues: https://github.com/pagerinc/hapi-redis/issues
- npm.io page: https://npm.io/package/@pager/hapi-redis

## Dependencies (1)

- [redis](https://npm.io/package/redis.md) 2.x

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 2.1.7 (latest) — 2020-03-09
- 2.1.6 — 2020-03-09
- 2.1.5 — 2020-03-08
- 2.1.4 — 2020-03-08
- 2.1.3 — 2020-03-07
- 2.1.2 — 2020-03-06
- 2.1.1 — 2020-03-05
- 2.1.0 — 2019-12-19
- 2.0.2 — 2019-08-23
- 2.0.1 — 2019-07-23
- 2.0.0 — 2019-04-22
- 1.2.0 — 2019-02-21
- 1.1.1 — 2017-01-26
- 1.1.0 — 2016-09-07
- 1.0.1 — 2016-03-10
- … 1 more at https://npm.io/package/@pager/hapi-redis/versions

## README

# hapi-redis

A [node-redis] hapi plugin

[![CircleCI](https://circleci.com/gh/pagerinc/hapi-redis.svg?style=svg)](https://circleci.com/gh/pagerinc/hapi-redis)

## 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`](http://hapijs.com/api#serverapp) common namespace.

## Examples

```js
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.: 

```javascript
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`:

```bash
$ 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].

[node-redis]: https://github.com/NodeRedis/node_redis
[hapi-ioredis]: https://github.com/cilindrox/hapi-ioredis

---
_Source: https://npm.io/package/@pager/hapi-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
