Skip to content

Instantly share code, notes, and snippets.

@Charuru
Created February 11, 2016 03:02
Show Gist options
  • Save Charuru/ab6e1d3157cbed3ddf22 to your computer and use it in GitHub Desktop.
Save Charuru/ab6e1d3157cbed3ddf22 to your computer and use it in GitHub Desktop.
/**
* Created by djarno on 1/19/2016.
*/
var classname = "[c/ramstats.js]";
var redis = require("redis");
var debug = require("../debug.js");
module.exports = {
depleteUser: function (userJSON, callback) {
var client = redis.createClient();
client.del([userJSON.uid], function (err) {
if(!err) {
debug.callbackDebug(classname, "Successfully depleted user.");
client.quit();
callback("", "succes");
}
});
},
//Make sure where passing JSON (json.uid).
getUser: function (userJSON, callback) {
var client = redis.createClient();
client.hget([userJSON.uid, "0"], function (err, ramData) {
if(!err) {
client.quit();
debug.callbackDebug(classname, "Successfully received user.");
callback("", JSON.parse(ramData));
}
});
},
toggleUserBusy: function(userJSON, callback) {
var client = redis.createClient();
client.hset([userJSON.uid, "0", JSON.stringify(userJSON)], function (err, data) {
if(!err) {
debug.callbackDebug(classname, "Successfully toggled user.");
client.quit();
callback("", userJSON);
}
});
},
updateUser: function(userJSON, callback) {
var client = redis.createClient();
client.hset([userJSON.uid, "0", JSON.stringify(userJSON)], function (err, data) {
if(!err) {
debug.callbackDebug(classname, "Successfully updated user.");
client.quit();
callback("", userJSON);
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment