From fb6aaf588ec5b9f591a3932e9f6d6e67958f9661 Mon Sep 17 00:00:00 2001 From: Igor Sidorov Date: Mon, 26 Sep 2016 16:46:00 +0300 Subject: [PATCH] Show redis logging only if debug is on --- middleware/cache/providers/redis.js | 32 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/middleware/cache/providers/redis.js b/middleware/cache/providers/redis.js index 3ddb436d..18d3e1dc 100644 --- a/middleware/cache/providers/redis.js +++ b/middleware/cache/providers/redis.js @@ -11,6 +11,8 @@ exports = module.exports = function(cacheConfig) { var client = null; + var debug = false; + var r = {}; r.init = function(callback) @@ -27,9 +29,13 @@ exports = module.exports = function(cacheConfig) redisEndpoint = process.env.CLOUDCMS_CACHE_REDIS_ENDPOINT; } - var redisOptions = {}; + debug = cacheConfig.debug; + + if (typeof(debug) === "undefined") { + debug = false; + } - //redis.debug_mode = true; + var redisOptions = {}; client = redis.createClient(redisPort, redisEndpoint, redisOptions); @@ -41,14 +47,18 @@ exports = module.exports = function(cacheConfig) if (seconds <= -1) { client.set([key, JSON.stringify(value)], function(err, reply) { - console.log("[redis] write -> reply = " + reply); + if (debug) { + console.log("[redis] write -> reply = " + reply); + } callback(err, reply); }); } else { client.set([key, JSON.stringify(value), "EX", seconds], function(err, reply) { - console.log("[redis] write.ex -> reply = " + reply); + if (debug) { + console.log("[redis] write.ex -> reply = " + reply); + } callback(err, reply); }); } @@ -58,7 +68,9 @@ exports = module.exports = function(cacheConfig)     {         client.get([key], function(err, reply) { - console.log("[redis] read -> reply = " + reply); + if (debug) { + console.log("[redis] read -> reply = " + reply); + }              var result = null;             try @@ -84,12 +96,16 @@ exports = module.exports = function(cacheConfig) r.keys = function(prefix, callback)     { - console.log('[redis] prefix = ' + prefix); + if (debug) { + console.log('[redis] prefix = ' + prefix); + }         client.keys([prefix + '*'], function(err, reply) { -            console.log("[redis] keys -> reply = " + reply); + if (debug) { + console.log("[redis] keys -> reply = " + reply); + }             callback(err, reply);         });     }; return r; -}; \ No newline at end of file +};