python安装rejson

1
pip3 install rejson

Python代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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()

参数

1
2
3
4
5
6
7
8
9
10
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 返回字符串

参考:
https://pypi.org/project/rejson/