1.0.1 • Published 7 years ago

@trigo/atrix-redis v1.0.1

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

atrix-redis

redis plugin for atrix microservice framework

atrix redis plugin automaticaly sets up the connection to your redis server using ioredis library

Compatibility

atrix-redis < 1.0.0 works with atrix < 6.0.0 atrix-redis >= 1.0.0 works with atrix >= 6.0.0

Features

  • configuration driven
  • multi connection/database mgmt

Installation

# install atrix framework
npm install -S @trigo/atrix

# install atrix-redis plugin
npm install -S @trigo/atrix-redis

# No need to install redis itself!

Usage & Configuration

handlers/GET.js

module.exports = (req, reply, service) => async {
	// access model class for connection "m1"
	const redisClient = service.dataConnections.m1.client;
	await redisClient.set(key, value);
	
	...
}

index.js

'use strict';

const atrix = require('@trigo/atrix');
const path = require('path');

atrix.addService({
	name: 'redis', 
	endpoints: {
		http: {
			// declare port to bind
      port: 3007,

      // the directory containing the handler files
      handlerDir: `${__dirname}/handlers`,
   	},
  },
	// declare a dataSource config section
	dataSource: {
		// name of the data source
		m1: {
			// type of data connection
			type: 'redis',
			// connection configuration
			config: {
				// redis host
				host: 'localhost',

				// redis port
				port: 6379,

				// optional: password
				password: 'redis-secret-password',

				// optional: db to user
				db: 1
			},
		},
		m2: {
			type: 'redis',
			config: {
				host: 'redis',
				port: 6379,
			},
		},
	},
});

// start service. 
// This will wait for the mongo connection to be available before starting up. 
// When conection(s) is lost after initial startup the plugin automatically tries to reconnect  
svc.start();

Run service with node index.js