I have created a redis client module named redisConnection.js
. It's contents are as follows
var redis = require('redis').createClient();
exports.exposeConnection = function(){
return redis;
};
Now whenever I want to get make use of redis I just require
the module and call the exposeConnection
method. I wanted to know if this is right way to reuse the connection. I am hoping that redis connection is being instantiated only once and not every time I call the module. If not is there a better way reuse it?
redisConnection.js
files, only one connection should be created among allrequire()
s. – Debivar redis = require('redis'); GLOBAL._REDISCLIENT = redis.createClient(port, server);
– Senlac