Python3 下 Redis 默认返回 bytes 类型数据,而 Python3 下 bytes 类型和 str 类型不能直接互用,容易出错,解决方法是在建立 Redis 连接的时候将 decode_responses 设置为 True,表示将返回的 bytes 数据解码为 str 数据


    def __init__(self, host='localhost', port=6379,
                 db=0, password=None, socket_timeout=None,
                 socket_connect_timeout=None,
                 socket_keepalive=None, socket_keepalive_options=None,
                 connection_pool=None, unix_socket_path=None,
                 encoding='utf-8', encoding_errors='strict',
                 charset=None, errors=None,
                 decode_responses=False, retry_on_timeout=False,
                 ssl=False, ssl_keyfile=None, ssl_certfile=None,
                 ssl_cert_reqs='required', ssl_ca_certs=None,
                 max_connections=None, single_connection_client=False,
                 health_check_interval=0):

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2021-06-20
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-01-11
  • 2022-01-12
相关资源
相似解决方案