Skip to content

Instantly share code, notes, and snippets.

@siculars
Created September 27, 2010 20:46
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 siculars/599795 to your computer and use it in GitHub Desktop.
Save siculars/599795 to your computer and use it in GitHub Desktop.
//save the object with no key in riak. riak will autogen a key
riak.save('posts','',{content: content, tags: vettedPostTags })(
//success callback
function (d,m){
//return an int of lastmodified in meta
var paresedDate = Date.parse(m.headers.date);
//push riak key to a mostrecents list in redis
redis.lpush('mostrecent',m.key);
//for each tag
for (var i = 0, len = vettedPostTags.length ; i < len ; i++){
vpt = vettedPostTags[i].replace(/[^A-Za-z0-9]/g,'_');
var redis_post_tag_key = 'tag_' + vpt;
var redis_post_ztag_key = 'zset_tag_' + vpt;
//push each tag to another list
redis.lpush(redis_post_tag_key,m.key);
//sys.puts(m.headers.date);
//add tag into a sorted set with the int(date) as the score
redis.zadd(redis_post_ztag_key,paresedDate,m.key);
}
//return the new key just saved
res.simpleJSON(200, { key: m.key });
},
//error callback
function (d,m){
res.simpleJSON(400, { error: 'Could not post.' });
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment