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
评论列表
文章目录