Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghostbar/hapi-hiredis
Hapi's hiredis plugin
https://github.com/ghostbar/hapi-hiredis
Last synced: 8 days ago
JSON representation
Hapi's hiredis plugin
- Host: GitHub
- URL: https://github.com/ghostbar/hapi-hiredis
- Owner: ghostbar
- License: isc
- Created: 2015-01-03T07:45:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-23T00:11:36.000Z (about 9 years ago)
- Last Synced: 2024-10-20T11:28:18.501Z (26 days ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
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.Install
-------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();server.register({
register: require('hapi-hiredis'),
opts: { url: 'redis://:[email protected]: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`.
server.route({
method: 'GET',
path: '/hashes',
handler: function (request, reply) {
var redis = request.server.plugins['hapi-hiredis'].client;
redis.hgetall('hashes', function (err, obj) {
reply(obj);
});
}
}, {
method: 'GET',
path: '/session',
handler: function (request, reply) {
var redis = this.redis;
redis.get('session', function (err, obj) {
reply(obj);
});
}
});If for any reason you need to use the `redis` library, then you can use it from `server.plugins['hapi-hiredis'].library`.
License
-------Licensed under the terms of the ISC. A copy of the license can be found in the file `LICENSE`.
© 2015, Jose-Luis Rivas ``