代码
python
import pickle
import redis
class Request:
def __init__(self):
self.url = "https://blog.csdn.net/MarkAdc"
self.method = "GET"
req = Request()
print(req.__dict__)
# 把req对象进行序列化
_req = pickle.dumps(req)
# 序列化后放进redis
key = "reqs"
client = redis.Redis(host="localhost", port=6379, db=0)
client.lpush(key, _req)
# 反序列化,获取到原来的req对象
value = client.lpop(key)
if value:
req = pickle.loads(value) # 反序列化
print(req.__dict__)