getComments: function(postId, start, count, cb) { var key = commentListPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } if (!start) { start = '+inf'; } else { start = '(' + start; } client.zrevrangebyscore(key, start, 0, 'limit', 0, count, function(err, comments) { if (err) { cb(err); } else { var commentList = []; for (var i = 0; i < comments.length; i++) { var commentObj = JSON.parse(comments[i]); commentList.push(commentObj); } cb(0, commentList); } }); }); },
getPostsByIds: function(postIds, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } var multi = client.multi(); for (var i = 0; i < postIds.length; i++) { var key = postPrefix + postIds[i]; multi.hgetall(key); } multi.exec(function(err, posts) { var tmp = []; for (var i = 0; i < posts.length; i++) { if(posts[i]) { posts[i].tags = JSON.parse(posts[i].tags); posts[i].time = parseInt(posts[i].time); posts[i].commentCount = parseInt(posts[i].commentCount); posts[i].viewCount = parseInt(posts[i].viewCount); tmp.push(posts[i]); } } cb(err, tmp); }); }); },
addPostToCateList: function(cate, postId, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.zadd(postCateListPrefix + cate, parseInt(postId), postId, function(err) { cb(err); }); }); },
getPostCount: function(cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.zcard(postListKey, function(err, count) { cb(err, count); }); }); },
addPostIdToList: function(postId, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.zadd(postListKey, parseInt(postId), postId, function(err) { cb(err); }); }); },
deleteComment: function(postId, commentId, cb) { var key = commentListPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.zremrangebyscore(key, parseInt(commentId), parseInt(commentId), function(err) { cb(err); }); }); },
getCommentCount: function(postId, cb) { var key = postPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.hget(key, 'commentCount', function(err, count) { cb(err, count); }); }); },
incVV: function(postId, count, cb) { var key = postPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.hincrby(key, 'viewCount', count, function(err) { cb(err); }); }); },
addComment: function(postId, commentInfo, cb) { var key = commentListPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } var valmap = blogDao.convertMap(commentInfo); client.zadd(key, commentInfo.id, JSON.stringify(commentInfo), function(err) { cb(err); }); }); },
addPostById: function(postId, postInfo, cb) { var key = postPrefix + postId; redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } var valmap = blogDao.convertMap(postInfo); client.hmset(key, valmap, function(err) { cb(err); }); }); },
getPostIdList: function(start, count, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } if (!start) { start = '+inf'; } else { start = '(' + start; } client.zrevrangebyscore(postListKey, start, 0, 'limit', 0, count, function(err, ids) { cb(err, ids); }); }); },
delPostIdFromCateList: function(cate, postId, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } var zsetKey; if(cate) { zsetKey = postCateListPrefix + cate; } else { zsetKey = postListKey; } client.zrem(zsetKey, postId, function(err) { cb(err); }); }); },
delPostById: function(postId, cate, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } client.del(postPrefix + postId, function(err1) { client.zrem(postListKey, postId, function(err2) { if(cate) { client.zrem(postCateListPrefix + cate, postId, function(err3) { cb(err1 || err2 || err3); }); } else { cb(err1 || err2); } }); }); }); },
getPostIdsByCate: function(cate, start, count, cb) { redisFactory(rp.providerSettings.dao.redis, function(err, client) { if (err) { cb(err); return; } if (!start) { start = '+inf'; } else { start = '(' + start; } var zsetKey; if(cate) { zsetKey = postCateListPrefix + cate; } else { zsetKey = postListKey; } client.zrevrangebyscore(zsetKey, start, 0, 'limit', 0, count, function(err, ids) { cb(err, ids); }); }); },