推荐学习书目
› 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 · 5900 views
    This topic created in 4800 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
        1
    llbgurs  
       Aug 7, 2013
    看看Django或者flask的signal怎么实现的,比如 http://flask.pocoo.org/docs/signals/
    felix021
        2
    felix021  
       Aug 7, 2013   ❤️ 1
    这个应该为每个用户维护一个队列(适合在尾部添加新id的数据结构)用来存timeline,A新增一个消息的时候分配一个消息id,然后把这个消息id加入到关注A的所有用户的timeline末尾。

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