Created
August 16, 2014 12:23
-
-
Save srfrnk/5b341ccc0a64275661ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("requirejs").define("models/redisHelper", [], function () { | |
var Q = require("q"); | |
var redis = require("redis"); | |
var connectionOptions = JSON.parse(process.env.REDIS_CONNECTION_OPTIONS); | |
var client = redis.createClient(connectionOptions.port, connectionOptions.host, {}); | |
client.auth(connectionOptions.password, function (err, reply) { | |
if(!!err) | |
{ | |
console.log(err); | |
} | |
}); | |
return { | |
set: function (key, value) { | |
client.set(key,value); | |
}, | |
get: function (key) { | |
var q= Q.defer(); | |
client.get(key, function (err, reply) { | |
if(!err) | |
{ | |
q.resolve(reply); | |
} | |
else | |
{ | |
console.log(err); | |
q.reject(err); | |
} | |
}); | |
return q.promise; | |
}, | |
del: function (key) { | |
var q= Q.defer(); | |
client.del(key, function (err, reply) { | |
if(!err) | |
{ | |
q.resolve(reply); | |
} | |
else | |
{ | |
console.log(err); | |
q.reject(err); | |
} | |
}); | |
return q.promise; | |
}, | |
expire: function (key,maxAge) { | |
client.expire(key,maxAge); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment