복붙노트

[REDIS] 어떻게 SO 후 레디 스로 기록 될 것인가? [닫은]

REDIS

어떻게 SO 후 레디 스로 기록 될 것인가? [닫은]

나는 한 레디 스를 사용하여 유래를 구현하는 것이 방법을 생각했다. 이것에 가장 어려운 부분은 내가 설명을하고 난 각각의 의견 upvotes을 얻을 루프를하지 않는 방법으로 그것을 가지고하는 방법입니다. 나는 바이너리 덩어리를 수정하기로 결정했다. UVComment 복잡한의 종류이다.

매번 나는 세트 또는 목록을 사용하여 종료 해시를 사용하는 생각을했다. 내가 실수를하면 나는 놀라지 않을 것이다, 그래서 나는 레디 스 꽤 새로운 해요. 이 잘 설계되어 있습니까?

postId=incr postCount
MULTI
rpush p:postId bin[IsQuestion,authorId,title,body,tags,datetimestamp]
foreach tag in tags
    sadd tags:tag postId
EXEC
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
//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
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
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
lrange p:postId -1 -1 //current revision
scard pUV:postId
scard pDV:postId
comments=lrange post_comment:postId 0 -1 //get all comments

해결법

    from https://stackoverflow.com/questions/12221882/how-would-so-post-be-written-with-redis by cc-by-sa and MIT license