Skip to content

Instantly share code, notes, and snippets.

@srfrnk
Created August 16, 2014 12:23
Show Gist options
  • Save srfrnk/5b341ccc0a64275661ca to your computer and use it in GitHub Desktop.
Save srfrnk/5b341ccc0a64275661ca to your computer and use it in GitHub Desktop.
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