bulletproof-nodejs icon indicating copy to clipboard operation
bulletproof-nodejs copied to clipboard

Redis client

Open Wiz1991 opened this issue 4 years ago • 2 comments

How would you wrap up redis and use it as a dependency? I created a loader for it and injected it but i have no type support or anything else?

Wiz1991 avatar Feb 25 '21 09:02 Wiz1991

Can you share an example code?

warapitiya avatar Mar 03 '21 00:03 warapitiya

Here is what I did with redis.

// redis.js 
const uitl = require('util');
const redis = require('redis');
const config = require('../config');

module.exports = () => {
  const client = redis.createClient(config.env.redis);
  client.get = uitl.promisify(client.get);
  return client;
};

// dependencyInjector.js
const { Container } = require('typedi');
const Redis = require('./redis');

module.exports = () => {

  Container.set('RedisClient', Redis());
};

You can find the whole code here.

dheeraj-rn avatar Jun 19 '21 14:06 dheeraj-rn