Created
August 7, 2013 18:08
-
-
Save guymorita/6176771 to your computer and use it in GitHub Desktop.
redis code
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
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
commented
Aug 7, 2013
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