database - how to implement nested comment system using redis efficiently -
i'm trying implement nested comment scheme using redis, illustration every article can have comments first layer comments, first layer comments can commented , create sec layer comments, , on, can have infinite layers. i'm using hashs, each key represents article, 1 field article info , 1 field comment, value of comment in xml format tags comment ids nested kid nodes. it's inefficient because each seek retrieve comment, have of them whole. wondering if there's other more efficient way this? thanks
i think first step thinking in relational database. example, simple scheme have next schema:
article ( id int, name text, body text ) comment ( id int, article_id int, parent int, author text, body text )
converting redis takes little thinking. want create sure info structures utilize right ones provide fastest times. here different keys/key structures utilize in implementing system:
article:<id>
- hash stores article info , has next keys: name
- name of article body
- body text of article article-id
- auto-increment value article ids article-comments:<id>
- set of comment ids top-level comments on article id <id>
comment:<id>
- has stores comment info , has next keys: author
- comment author body
- body text of comment comment-id
- auto-increment value comment ids comment-children:<id>
- set of comment ids represent comments replys comment id <id>
the steps adding new comment follows:
incrementcomment-id
create new hash key concatination of comment:
, value homecoming in step 1 fill in hash created in step 2 comment data if comment not have parent, add together id appropriate article-comments:<id>
set. if have parent, add together appropriate comment-children:<id>
set. database redis
No comments:
Post a Comment