解決python3下讀取redis返回byte類型的問題

咱們首先查看redis鏈接的構造方法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便可socket

sr = StrictRedis(decode_responses=True)
相關文章
相關標籤/搜索