Skip to content

Instantly share code, notes, and snippets.

@guymorita
Created August 7, 2013 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guymorita/6176771 to your computer and use it in GitHub Desktop.
Save guymorita/6176771 to your computer and use it in GitHub Desktop.
redis code
db.js
var redis = require("redis");
var config;
module.exports = function() {
client = redis.createClient(6379,'127.0.0.1');
client.flushdb();
// client = redis.createClient(6379,'nodejitsudb6625264643.redis.irstack.com');
// client.auth("nodejitsudb6625264643.redis.irstack.com:f327cfe980c971946e80b8e975fbebb4");
};
main.js
require('./db.js')();
input.js
exports.input = function(){
// var redis = require("redis"),
var config = require('./config.js').config(),
algo = require('./algorithms.js');
var updateSequence = function(userId, itemId, callback){
algo.updateSimilarityFor(userId, function(){
algo.updateWilsonScore(itemId, function(){
algo.updateRecommendationsFor(userId, function(){
callback();
});
});
});
};
return {
liked: function(userId, itemId, callback){
client.sismember([config.className, itemId, 'liked'].join(":"), userId, function(err, results){
if (results === 0){
client.zincrby([config.className, 'mostLiked'].join(":"), 1, itemId);
}
client.sadd([config.className, userId,'liked'].join(':'), itemId, function(err){
client.sadd([config.className, itemId, 'liked'].join(':'), userId, function(err){
updateSequence(userId, itemId, callback);
});
});
});
},
disliked: function(userId, itemId, callback){
client.sismember([config.className, itemId, 'disliked'].join(":"), userId, function(err, results){
if (results === 0){
client.zincrby([config.className, 'mostDisliked'].join(":"), 1, itemId);
}
client.sadd([config.className, userId, 'disliked'].join(':'), itemId, function(err){
client.sadd([config.className, itemId, 'disliked'].join(':'), userId, function(err){
updateSequence(userId, itemId, callback);
});
});
});
}
};
};
@stevemanuel
Copy link

module.exports = function() {
  //client = redis.createClient(6379,'127.0.0.1');
  //client.flushdb();
  client = redis.createClient(6379,'nodejitsudb6625264643.redis.irstack.com');
  client.auth("nodejitsudb6625264643.redis.irstack.com:f327cfe980c971946e80b8e975fbebb4", function(err, reply) {
    if (err) {  console.log("Error: "+err); }
    else { console.log("should be connected. Reply: "+reply); }
  });
};

@stevemanuel
Copy link

PORT = process.env.REDIS_PORT;
HOST = process.env.REDIS_HOST;

    client = redis.createClient(PORT, HOST);

    client.auth(process.env.REDIS_AUTH, function(error, reply) {

      if (error) {

        console.log("(!) Redis auth failed: " + error);

      }
      else {

        console.log("Connected to Redis: " + reply);

      }

    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment