celery + redis demo
程序员文章站
2022-04-08 16:07:01
...
- 环境准备
pip install -U celery[redis]
2.创建task
from celery import Celery
import time
app = Celery('test', backend='redis://localhost:6379/0', broker='redis://localhost:6379/0')
@app.task
def hello():
time.sleep(10)
return 'hello world'
@app.task
def fun():
return 'fun'
3.创建worker
celery worker -A test --loglevel=debug
4.测试
from test import fun
if __name__ == '__main__':
print fun.delay().get()