推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
hustlzp
V2EX  ›  Python

如何实现关注的消息推送?

  •  
  •   hustlzp · Aug 7, 2013 · 6030 views
    This topic created in 4847 days ago, the information mentioned may be changed or developed.
    比如用户A会产生一些消息,如何将这些消息推送给关注A的用户?

    自己的方法是:专门建立一个存储消息的数据表,字段有2个:user(消息发起者)+message(消息内容)。

    然后A每发出一条消息,就向这个表插入一条数据。关注A的用户在登陆网站后,就在这个表中查询user=A 的所有条目,生成的消息展示出来。

    不知道大家是怎么做的?
    9 replies  •  1970-01-01 08:00:00 +08:00
    llbgurs
    llbgurs
    Aug 7, 2013
    1
    看看Django或者flask的signal怎么实现的,比如 http://flask.pocoo.org/docs/signals/
    felix021
    felix021
    Aug 7, 2013❤️1
    2
    这个应该为每个用户维护一个队列(适合在尾部添加新id的数据结构)用来存timeline,A新增一个消息的时候分配一个消息id,然后把这个消息id加入到关注A的所有用户的timeline末尾。

    redis的list是一个很合适的实现。
    hustlzp
    hustlzp
    OP
    Aug 7, 2013
    4
    @felix021 嗯,这样更加有效率!
    hustlzp
    hustlzp
    OP
    Aug 7, 2013
    5
    @no13bus nice 教程,好好看一下。
    Frannk
    Frannk
    Aug 7, 2013
    6
    补充一下:
    最好进入队列 异步的处理推送
    cadl
    cadl
    Aug 7, 2013
    7
    推模式和拉模式 感觉要具体情况分析
    hustlzp
    hustlzp
    OP
    Aug 7, 2013
    8
    @Frannk 恩,貌似Celery+RabbitMQ就是干这事儿的吧。
    hustlzp
    hustlzp
    OP
    Aug 7, 2013
    9
    @ctrlaltdeletel 还需要在实践中摸索
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1857 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 08:22 · PVG 16:22 · LAX 00:22 · JFK 03:22
    ♥ Do have faith in what you're doing.