解决python3下读取redis返回

发布时间:2019-10-17 09:07:47编辑:auto阅读(2493)

    我们首先查看redis连接的构造方法

        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=None, ssl_ca_certs=None,
                     max_connections=None):

    decode_responses=fase这个参数决定返回结果是否decode,所以只需要设置连接将其改为true即可

    sr = StrictRedis(decode_responses=True)

关键字