环境准备
1 安装celery 和redis库
pip install celery-with-redis
卸载 3.0以上版本的redis,安装2.1版本的redis 注:此处是一个坑
pip uninstall redis
pip install redis==2.10.6
2 安装本地redis数据库 此处不做说明,后续对数据库梳理时再做说明
3 开始celery编码
# -*- coding: utf-8 -*-
# @Author: Roble
# @Date: 2019-10-15 20:24:55
# @Last Modified by: Roble
# @Last Modified time: 2019-12-12 22:15:15
import time
from celery import Celery
broker = 'redis://127.0.0.1:6379'
backend = 'redis://127.0.0.1:6379/0'
app = Celery('tasks', broker=broker, backend=backend)
@app.task
def add(x, y):
#time.sleep(1) # 模拟耗时操作
print