Created
September 27, 2010 20:46
-
-
Save siculars/599795 to your computer and use it in GitHub Desktop.
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
//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