python - Celery:Redis 作为代理离开任务元键

标签 python redis celery

我有一个以 Redis 作为代理的 celery 应用。

代码由以下循环组成:

running = []
res = add.apply_async([1,2], queue='add')
running.append(res)

while running:
    r = running.pop()
    if r.ready():
        print r.get()
    else:
        running.insert(0,r)

一切正常,但是当我 redis-cli 进入 redis 并执行 keys * 我看到一堆 celery-task-meta 键。

他们为什么不清理?
那些是干什么用的?

--

[编辑]

我读过 CELERY_TASK_RESULT_EXPIRES 设置。
Redis中的task key是否可以在读取结果后立即清理,而不是等到过期时间?

最佳答案

来自 Celery 文档:

AsyncResult.forget()
   Forget about (and possibly remove the result of) this task.

你必须先 r.get() 然后 r.forget()

但是,您不需要清理 key 。 对于,doc说:

CELERY_TASK_RESULT_EXPIRES

默认为 1 天后过期。

关于python - Celery:Redis 作为代理离开任务元键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34127864/

相关文章:

database - 为共享计数器对数据库进行分区

django + celery + redis + postgres 挂了

python - celery:如何重命名任务并将其路由到队列

python - Mnist识别使用keras

python - 从拆分的 .csv 数据集制作线性回归模型的最佳方法?

python - Mongodb FindAndModify 多进程使用问题

python - Python 中针对此 Codejam 问题的更快或更节省内存的解决方案

python - 如何在redis缓存中使用django-redis hset操作

ruby-on-rails - 在部署到 EC2 之后,sidekiq 现在报告 SocketError : getaddrinfo: Name or service not known

task - 如何清理 celery_taskmeta?