object - > json
This is called serialization.
r = redisconnect(0)
prev_topicList_redis = r.get("BIGDATA.NEWS_CLUSTER:cn.dup_by_generator.3")
#read from redis, but the prev_topicList is a dict rather than a object
prev_topicList = json.loads(prev_topicList_redis)
#covert the object to the json format
topicList_json = json.dumps(topicList, default=jdefault, indent = 2, ensure_ascii=False).encode('utf-8')
r.set("BIGDATA.NEWS_CLUSTER:cn.dup_by_generator.3", topicList_json)
def jdefault(o):
if isinstance(o, datetime):
return o.isoformat()
return o.__dict__