Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions middleware/cache/providers/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ exports = module.exports = function(cacheConfig)
{
var client = null;

var debug = false;

var r = {};

r.init = function(callback)
Expand All @@ -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);

Expand All @@ -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);
});
}
Expand All @@ -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
Expand All @@ -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;
};
};