@kos-ng-it-konsult/redis
v0.0.4
Published
KOS NG IT Konsult redis wrapper for handling redis connection
Downloads
1
Readme
@kos-ng-it-konsult/redis
This is a wrapper class that allows creation of redis connection. It uses ioredis (https://github.com/luin/ioredis) as it's redis client.
Quick Start
Install
$ npm i --save @kos-ng-it-konsult/redis
Basic Usage
// Require the library
const redis_manager = require('@kos-ng-it-konsult/redis');
// Create a new instance of the library
let redis = new redis_manager();
// Create connections to redis server;
try {
const connection_array = [
{
name: '',
url: 'redis://@127.0.0.1:6379/0' //connect to 127.0.0.1:6379, db 0, without authentication
},
{
name: '',
config: {
port: 6379,
host: '127.0.0.1',
family: 4, // IPV4 or IPV6
password: '',
db: 1
}
}
];
redis = redis.connect(connection_array);
// Add a new connection to existing connections
redis.newConnection({
name: 'conn_c',
config: {
port: 6379,
host: '127.0.0.1',
family: 4, // IPV4 or IPV6
password: '',
db: 2
}
});
// Get a single redis connection
const single_connection = redis.connections('conn_a'); // Gets connection with name conn_a
// Use single connection to access redis store
single_connection.set('org_name', 'KOS-NG IT Konsult');
single_connection.get('org_name', function (error, result) {
console.log('Redis(org_name) =>', result);
});
single_connection.del('org_name');
} catch (error) {
console.error(error);
}
Running the Example
To run the example, simply run the command:$ node ./example/sample.js
Press CTRL+C
to exit the script when done.
Running Tests
Make sure your redis server is running on 127.0.0.1:6379, then run:$ npm test