initialize.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:JimV-N 作者: jamesiter 项目源码 文件源码
def redis_init_conn(cls):
        """
          * Added TCP Keep-alive support by passing use the socket_keepalive=True
            option. Finer grain control can be achieved using the
            socket_keepalive_options option which expects a dictionary with any of
            the keys (socket.TCP_KEEPIDLE, socket.TCP_KEEPCNT, socket.TCP_KEEPINTVL)
            and integers for values. Thanks Yossi Gottlieb.
            TCP_KEEPDILE ?????????????????????keepalive?????????
            TCP_KEEPINTVL ??????????????????
            TCP_KEEPCNT ??????????????????
        """
        import socket
        _r = redis.StrictRedis(host=cls.config.get('redis_host', '127.0.0.1'), port=cls.config.get('redis_port', 6379),
                               db=cls.config.get('redis_dbid', 0), decode_responses=True, socket_timeout=5,
                               socket_connect_timeout=5, socket_keepalive=True,
                               socket_keepalive_options={socket.TCP_KEEPIDLE: 2, socket.TCP_KEEPINTVL: 5,
                                                         socket.TCP_KEEPCNT: 10},
                               retry_on_timeout=True)

        try:
            _r.ping()
        except redis.exceptions.ResponseError as e:
            logger.warn(e.message)
            _r = redis.StrictRedis(
                host=cls.config.get('redis_host', '127.0.0.1'), port=cls.config.get('redis_port', 6379),
                db=cls.config.get('redis_dbid', 0), password=cls.config.get('redis_password', ''),
                decode_responses=True, socket_timeout=5, socket_connect_timeout=5, socket_keepalive=True,
                socket_keepalive_options={socket.TCP_KEEPIDLE: 2, socket.TCP_KEEPINTVL: 5,
                                          socket.TCP_KEEPCNT: 10},
                retry_on_timeout=True)

        _r.client_setname(ji.Common.get_hostname())
        return _r
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号