C
C
Cortess2019-04-09 20:43:03
PHP
Cortess, 2019-04-09 20:43:03

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?
e02ef49f920cb74a7b10141e0efe5645.png
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");
    }

And this is the display code
<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

1 answer(s)
D
Dmitry Bay, 2019-04-09
@Cortess

Maybe you should try using ordered sets?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question