bulletproof-nodejs
bulletproof-nodejs copied to clipboard
Redis client
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?
Can you share an example code?
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.