构建“消息读取”的解决方案Redis 中的类型队列系统?
我不完全确定 Redis 是解决此类问题的最佳工具,但我认为这是可能的。很多时候,您想向所有用户发送一条消息。几乎就像一个系统范围的新闻条目。您要确保用户不会多次看到此消息,他们应该只在登录时看到一次,之后在发布新条目之前他们永远不会看到该新闻部分。
我认为在 MySQL 中保留一个表,为用户每次读取消息时设置一个布尔列,这是一种低效的方法。您无法真正归档这样的表,因为如果这样做,您将不知道用户已阅读哪些消息以及未阅读哪些消息。
如果这可以使用 Redis pub/sub 完全在内存中完成,那就太好了。消息读取类型系统有哪些策略?
I'm not entirely sure Redis is the best tool for something like this, however I think it is possible. Many times there is a message you want to send to all of your users. Almost like a system wide news entry. You want to make sure that the user does not see this message more than once, they should only see it once on login, and after that they should never see that news section until a new entry has been published.
I think keep a table in MySQL that sets a boolean column for every time a user has read a message as an inefficient way of doing this. You can't really archive a table like that, because if you do, you won't know what messages a user has read and which they haven't.
It would be great if this can be done completely in memory using Redis pub/sub. What are some strategies for a messages read type system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您可以利用 redis 的 pub/sub 功能,也可以使用 comet.io 来实现 - 服务器将消息推送到客户端。如果这就是您想要做的,我可以详细说明一下,但我不完全确定系统是否必须对于您的用例来说那么复杂。使用 pubsub/comet 从前端到后端实现这一切并不是一件容易的任务,尽管可行并且有时需要/问题的正确解决方案。
一个可能也适合您的更简单的方法怎么样:
创建一个带有
creation_date
日期时间字段的news
表。将last_seen_news_date
字段添加到您的user
表中,为所有用户将其设置为过去的某个日期。当用户加载页面时,按如下方式查询新闻项:
然后使用当前日期时间或最新新闻文章的日期时间更新
last_seen_news_date
。Of course you could leverage redis pub/sub capabilities and maybe use socket.io for comet – the server pushes messages down to the client. If thats what you want to do I can elaborate a bit more about it, but I´m not entirely sure if the system has to be that complicated for your usecase. Implementig it all from frontend to backend with pubsub/comet is not an easy task, although doable and sometimes required/the right solution for the problem.
How about a simpler approach that might work out for you, too:
Create a
news
table with acreation_date
datetime field. Add alast_seen_news_date
field to youruser
table, set it for all users to some date in the past.When a user loads the page, query the news items like this:
Then update the
last_seen_news_date
with the current datetime or maybe the datetime of the most recent news article.