推荐学习书目
› 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
a87150
V2EX  ›  Python

django 定时把 redis 缓存同步到数据库的最佳实践是什么?

  •  
  •   a87150 · Sep 17, 2017 · 5969 views
    This topic created in 3296 days ago, the information mentioned may be changed or developed.

    搞了一下午 celery 都没弄好,报 Apps aren't loaded yet.完全不知道怎么解决。

    9 replies  •  2017-09-18 09:31:36 +08:00
    Immortal
        1
    Immortal  
       Sep 17, 2017
    没有实践过,第一反应是任务计划

    不过,我怎么感觉怪怪的
    应该是数据先落地再做缓存 不应该是先缓存再落地 这样会有可能导致意外数据丢失的
    一般 up 主这种如果是落地耗时的业务 是不是应该考虑走异步 比如队列
    a87150
        2
    a87150  
    OP
       Sep 17, 2017
    @Immortal
    我是想把点击点赞这种不是很重要又很频繁的操作先用 redis 缓存,然后空闲时间一次性存到数据库。
    Immortal
        3
    Immortal  
       Sep 17, 2017
    @a87150 可以任务计划 或者 设定一个阀值 满多少落地一次
    a87150
        4
    a87150  
    OP
       Sep 17, 2017
    @Immortal 我就是想问用什么计划任务最简单方便
    Immortal
        5
    Immortal  
       Sep 17, 2017
    @a87150 写个脚本 然后配置到 crontab 不就好了...
    wekw
        6
    wekw  
       Sep 18, 2017
    最佳实践:别用 Python,用自带的二进制工具
    pepesii
        7
    pepesii  
       Sep 18, 2017 via iPhone
    Celery beat
    Crontab
    pepesii
        8
    pepesii  
       Sep 18, 2017 via iPhone
    又看了下,redis 搞个主从,然后在从机上去做定时任务,获取 size 大小,超过你的设置的阈值就同步嘛
    ToughGuy
        9
    ToughGuy  
       Sep 18, 2017   ❤️ 1
    managment/commands/sync_cache.py

    */5 * * * * python manage.py sync_cache
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1135 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:37 · PVG 01:37 · LAX 10:37 · JFK 13:37
    ♥ Do have faith in what you're doing.