当前位置:网站首页>flask项目celery使用redis sentinel中遇到的坑
flask项目celery使用redis sentinel中遇到的坑
2022-07-23 05:45:00 【Sindweller5530】
flask项目celery中报错Can’t reconnect until invalid transaction is rolled back
发现是celery的程序中有一处db.session.commit()没有处理异常,添加try except InvalidRequestError和db.session.rollback()后修复。之前一直是SQLAlchemyError。
celery中的数据库连接池大小限制与连接未释放
QueuePool limit of size 10 overflow 10 reached, connection timed out
已查询完毕使用的数据库连接未释放。
解决方案:自动释放连接。
参考:https://stackoverflow.com/questions/24956894/sql-alchemy-queuepool-limit-overflow
@app.teardown_appcontext
def shutdown_session(exception=None):
db.session.remove()
另外再把数据库连接池的大小调大一点。
celery+flask+redis+sentinel带密码如何配置和初始化
一开始直接设置REDIS_URL = "sentinel://:[email protected]:26379/0"报错:
ValueError: Couldn't import 'app.celery': Redis URL must specify one of the following schemes (redis://, rediss://, unix://)
以为是celery,但这实际上是初始化redis-client出现的问题。
将redis_client的初始化从Flask-redis改为redis.sentinel
# redis_client = FlaskRedis(app)
redis_client = Sentinel([('localhost', 26379)], socket_timeout=1, sentinel_kwargs={
'password': 'password'})
print(redis_client.discover_master("mymaster"))
# 打印结果示例:
# ('10.1.1.1', 6379)
# redis使用举例
这样解决了redis,那么之后解决celery的broker和result backend的配置
(mymaster是默认的主集群)
BROKER_URL = "sentinel://:[email protected]:26379/1"
BROKER_TRANSPORT_OPTIONS = {
'master_name': 'mymaster',
'socket_timeout': 1,
'sentinel_kwargs': {
'password': 'password'}
}
CELERY_RESULT_BACKEND = "sentinel://:[email protected]:26379/2"
CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS = BROKER_TRANSPORT_OPTIONS
边栏推荐
- Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 3
- 使用InfluxDB数据库的疑惑
- [AUTOSAR com 1. introduction to communication protocol stack]
- 堆的实现与堆排序实现
- Prometheus
- 常见排序--归并排序(递归和非递归)+计数排序
- 高分子合成工艺学复习考题
- Interpretation of the paper: iterative feature representation method to improve the prediction performance of N7 methylguanosine (m7G) sites
- Question bank of basic principles of steel structure
- Summary of video coding and decoding related data
猜你喜欢

【学习总结】

Redis——基础概念

Blog building five: drawing bed selection

【AUTOSAR COM 3.信号的收发流程TX/RX】

Navicat for MySQL 安装教程

匿名上位机v7波形显示

Using one-way linked list to realize queue
![[AUTOSAR com 1. introduction to communication protocol stack]](/img/ed/e61ca1e37817a81fc6eada54192876.png)
[AUTOSAR com 1. introduction to communication protocol stack]

常见的排序—交换排序
![[AUTOSAR cantp 1. learn the network layer protocol of UDS diagnosis]](/img/dc/51a4f091c623dbaaa4c174ebdae92a.png)
[AUTOSAR cantp 1. learn the network layer protocol of UDS diagnosis]
随机推荐
Talent column | can't use Apache dolphin scheduler? The most complete introductory tutorial written by the boss in a month
C语言:基于顺序表的学生管理系统,超级详细,全部都有注释,看完不懂来扇我。
[distinguish the meaning and usage of constant pointer and pointer constants const int * and int * const]
Prometheus
钢结构基本原理试题及答案
队列与堆的相互实现(纯c实现)
(1)ASIO
Object based - two classic classes
《Kubernetes in Action》第二章笔记
Upper and lower case letter conversion
Interpretation of the paper: "bert4bitter: a basic model for improving bitter peptide prediction based on transformer (BERT) bidirectional encoder representation"
钢结构基本原理题库
Blog building six: the method of binding your own domain name
OSI开放系统互联模型和TCP/IP模型
高电压技术学习总结
[AUTOSAR com 1. introduction to communication protocol stack]
基于UDP的群聊聊天室
用单向链表实现 队列
Simply realize the function of stack
1. Ten principles of Economics