【发布时间】:2020-12-08 04:49:18
【问题描述】:
我有以下 (tasks.py):
from celery import shared_task
from django.core.cache import cache
@shared_task
def test(param1: str) -> None:
with cache.lock("lock-1"):
print("hello")
当我执行test.delay() 时,没有打印任何内容,这让我相信cache.lock("lock-1") 有问题。
我使用 Redis 作为我的缓存和 Celery 后端,这是在 settings.py 中配置的。
这里有什么问题?如果django.core.cache 不能用作锁定机制(以确保一次只运行一个test,可以使用什么来代替?)谢谢!
【问题讨论】: