kv存储 - 怎样用 Redis 缓存微博的评论列表?
阿神
阿神 2017-04-22 08:59:41
0
2
604

我不知道微博的评论是不是用了Redis缓存,我只是拿他来做为一个例子而已。通用的场景是:用Redis缓存有序的对象列表,要求可以对对象进行增、删、查操作。

我以微博的评论来说,之前跟其它人交流时,是用zset或list。如果用zset,每个元素是评论id,评论时间做score,而评论的内容无法存储,只能根据id再查mysql等数据库。如果用list,每个元素是一个hash的json序列化(包含评论id,评论内容,评论时间等),这样的话貌似没有办法实现根据评论id删除评论了? 当然,list的元素也可直接用评论id,那这样的话,其实跟用zset差不多。

不知道大家有没有更好的方案实现“用Redis缓存有序的对象列表,要求可以对对象进行增、删、查、分页操作”

阿神
阿神

闭关修行中......

reply all(2)
阿神

If you use zset, each element is a comment id, and the content of the comment cannot be stored. You can only check mysql and other databases based on the id

zadd Weibo comment id comment id+comment content
The id is used as the scope. You can use the id to delete it, and the subsequent comment content can also be displayed.

I’ve seen this question before, but I didn’t reply at the time because the example you gave was hard to understand. No one has replied to you after so many days. Let me explain. Your example is hard to understand! The above solution can only be based on the actual example you mentioned.

阿神

Use a list to save the comment ID, and then save each comment as a hash with the ID as the key. In addition, you generally need to set expiration time for these keys

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template