Skip to content

Instantly share code, notes, and snippets.

@adityab
Created December 29, 2011 00:16
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 adityab/1530630 to your computer and use it in GitHub Desktop.
Save adityab/1530630 to your computer and use it in GitHub Desktop.
memecached code
// publish meme
everyone.now.publish = function(meme) {
if(meme.name && meme.text.line1 && meme.text.line2) {
db.collection('memes', function(err, collection) {
// add a date field and save
meme.date = Date.now();
collection.insert(meme, function(err) {
if(!err)
everyone.now.receiveMeme(meme);
});
});
}
};
// retrieve the latest few memes of a name. If there is no name, retrieve a mixture
everyone.now.getRecent = function(memeName) {
var client = this;
console.log("retrieving");
db.collection('memes', function(err, collection) {
if(memeName == undefined) {
collection.find( {}, { sort: [[ "date", "desc" ]], limit: 25 }).toArray( function(err, docs) {
client.now.getContent(docs);
});
}
else {
collection.find( {"name": memeName}, { sort: [[ "date", "desc" ]], limit: 25 }).toArray( function(err, docs) {
client.now.getContent(docs);
});
}
});
};
var everyone = require("now").initialize(server, { socketio: {'transports': ['xhr-polling'] }} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment