In order to support threaded comments, we need to change the structure a little bit. We need to start storing the ID of the parent comment as parent_id
for the comments, which are replies to existing comments. We will use the lists and hashes to store the comments. Instead of a single list per post, we will use multiple lists based on whether the comment is a child of another comment or a parent comment.
The following is the PHP code snippet that stores threaded comments in Redis:
function save_comment($post_id, $author, $comment, $parent_id = 0) { $isParent = false; if($parent_id === 0) { $isParent = false; } else { $isParent = true; $redis->hSet("comment:$parent_id", "hasChildren", 1); } $comment_data = array("comment_id" => $redis->incr("comments:id:next"), "parent_id" => $parent_id, "author" => $author, "text" => $comment, "post_id" => $post_id, "hasChildren" => 0, "time" => time()); if...