烧瓶的redis哨兵集成

Flask-Redis-Sentinel的Python项目详细描述


Travis CI

Flask Redis Sentinel支持使用Sentinel连接到Redis,也支持连接到Redis 没有它。

  • 支持Python2.7和3.3+
  • 使用apache license 2.0授权

安装

使用pip安装:

pip install Flask-Redis-Sentinel

基本用法

fromflask_redis_sentinelimportSentinelExtensionredis_sentinel=SentinelExtension()redis_connection=redis_sentinel.default_connection# Later when you create applicationapp=Flask(...)redis_sentinel.init_app(app)

可以使用redis+sentinelflask配置变量配置redis连接参数 URL方案:

redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?socket_timeout=0.1
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
redis+sentinel://:sentinel-secret-password@localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1

该扩展还支持redis py支持的url方案,用于直接连接到实例而无需sentinel:

redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0

也支持flask和redis样式的配置变量,以便于迁移,但是扩展将 记录不推荐警告

REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 0

如果同时存在redis_url和其他变量,则使用url。

使用单个sentinel群集创建多个连接池

fromflask_redis_sentinelimportSentinelExtensionredis_sentinel=SentinelExtension()master1=redis_sentinel.master_for('service1')master2=redis_sentinel.master_for('service2')slave1=redis_sentinel.slave_for('service1')

访问redis py的sentinel实例

fromflask_redis_sentinelimportSentinelExtensionfromflaskimportjsonify,Flaskapp=Flask('test')redis_sentinel=SentinelExtension(app=app)@app.route('/')defindex():slaves=redis_sentinel.sentinel.discover_slaves('service1')returnjsonify(slaves=slaves)

更改日志

v2.0.0

  • 连接现在是线程本地的,以避免redis主故障转移后出现争用情况
  • 删除了对redis{host,port,db}配置变量的支持

v1.0.0

  • 将URL处理代码移动到单独的库中,redis\u sentinel\u url

  • 向后不兼容更改:

    # Old
    redis+sentinel://host:port/service?slave=true
    

    现在应该写为:

    # New
    redis+sentinel://host:port/service?client_type=slave
    

v0.2.0

  • 使用配置变量而不是redis{host,port,db}即使使用了redis url
  • 小重构

v0.1.0

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java传递实现接口的内部类   java为什么managedbean方法在post请求中的过滤器调用之前调用   java Android应用程序在Android M,O上崩溃,登录A/libc时出错:tid 17938中的致命信号11(SIGSEGV),代码2,故障地址0x343a2944   java JPA存储库。findByAll()返回null,但数据库中存在所有内容   用于发送电子邮件的java Ant脚本   Java小程序HTML页面发生了奇怪的事情   在Postman的请求正文中传递多个JSON数据,并使用Jersy(JXRS)进入Java Rest API   无法强制转换java DAO类   10分钟后重新连接java   正则表达式如何在java中选择字符串直到某个字符   java我的输出有一些问题   Objective中的java时间段   java如何在新屏幕上基于按钮单击在webview中打开url   java哪个selenium版本与Firefox ESR 45.2.0兼容   java无法使用Apache Camel 3.1.0将XML转换为JSON