Python - 把对象序列化后放进Redis

import pickle import redis class Request: def __init__(self): self.url = "https://blog.****.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__)
上一篇:C#应用程序实现限制输入法


下一篇:pytorh学习笔记——cifar10(八) 阶段总结