pip3 install rejson
#!/bin/python3
# -*- coding=utf-8 -*-
import rejson
# 连接redis
rj = rejson.Client(host='localhost', port=6379, decode_responses=True)
def run():
obj={}
obj['a']="1"
obj['b']="2"
# 写入。返回值a为True时写成功
a = rj.jsonset('obj', '.', obj)
# 读取。b非None时读取到内容
b = rj.jsonget('obj', '.')
print(b)
return
if __name__ == '__main__':
run()
class Client(encoder=None, decoder=None, host: Text=..., port: int=...,
db: int=..., password: Optional[Text]=..., socket_timeout: Optional[float]=...,
socket_connect_timeout: Optional[float]=..., socket_keepalive: Optional[bool]=...,
socket_keepalive_options: Optional[Mapping[str, Union[int, str]]]=...,
connection_pool: Optional[ConnectionPool]=..., unix_socket_path: Optional[Text]=...,
encoding: Text=..., encoding_errors: Text=..., charset: Optional[Text]=...,
errors: Optional[Text]=..., decode_responses: bool=..., retry_on_timeout: bool=...,
ssl: bool=..., ssl_keyfile: Optional[Text]=..., ssl_certfile: Optional[Text]=...,
ssl_cert_reqs: Optional[Union[str, int]]=..., ssl_ca_certs: Optional[Text]=...,
max_connections: Optional[int]=...,)
host
redis地址
port
redis端口
decode_responses=True
返回字符串