Answer the question
In order to leave comments, you need to log in
How to sort comments on Redis?
Good afternoon, I made the output of comments on the page through redis.
But they are displayed in a strange order. Let's say a user with id 1 and id 2
Each of them wrote 3 comments, the user with id 2 has comments below, for some reason, and vice versa for the other user. How to sort by the time the comment was added?
Here is the code for the model that retrieves the comments from the base
public function showComments()
{
/* @var $redis Connection */
$redis = Yii::$app->redis;
return $redis->smembers("post:{$this->getId()}:comments");
}
<span class="show-comments">
<?php foreach ($post->showComments() as $comment): ?>
<?php echo $comment; ?>
<hr>
<?php endforeach; ?></span>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question