I was thinking how to implement the stackoverflow method using redis. The hardest part of this is how I have to make comments and have it in such a way that I don't get hung up on to get each comment up. I decided to change the binary piece. UVComment is kind of complicated.
Every time I thought about using hashes, I ended up using sets or a list. I am new to redis, so I wonβt be surprised if I make a mistake. Is it well designed?
CreatePost / Question (the same, except for the flag, is set and the tags are empty in the answers
postId=incr postCount MULTI rpush p:postId bin[IsQuestion,authorId,title,body,tags,datetimestamp] foreach tag in tags sadd tags:tag postId EXEC
UpdatePost / Question
WATCH p:postId //dont want a new revision in the meantime old=lrange p:postId -1 -1 //current but now old MULTI rpush p:postId bin[IsQuestion,authorId,title,body,tags,datetimestamp] //new revision foreach tag in old.tags srem tags:tag postId foreach tag in tags sadd tags:tag postId EXEC
Rating up / down message
//up sadd pUV:postId user srem pDV:postId user //down sadd pDV:postId user srem pUV:postId user //undo up/down srem pUV:postId user srem pDV:postId user
A comment:
commentId=incr commentCount multi SET comment_post:commentId postId //for later use when we flag comments. We'll need to know where in the db it is RPUSH post_comment:postId bin[authorId,text,HasBeenEdited,datetimestamp,commentId, UVCount] exec
UVComment
watch commentUV:commentId res=SISMEMBER commentUV:commentId userId if res>0 //already upvoted unwatch return watch post_comment:postId lrange post_comment:postId 0 -1 //then we find which index matches our commentId //modify UVCount MULTI lset post_comment:postId targetIndex modifiedData sadd commentUV:commentId userId EXEC
Getpostlogic
lrange p:postId -1 -1 //current revision scard pUV:postId scard pDV:postId comments=lrange post_comment:postId 0 -1 //get all comments
user34537
source share