python 转化object 到json 然后存入redis以及从redis读取
2015-08-19 16:28
686 查看
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__
ref
http://pythontips.com/2013/08/08/storing-and-loading-data-with-json/http://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object
/article/3898678.html
http://stackoverflow.com/questions/1458450/python-serializable-objects-json
相关文章推荐
- Redis集群进阶-添加新节点到集群
- 用redis实现微博关注关系
- Redis常用的命令(二)------key的基本操作
- Redis集群进阶-故障转移测试
- Redis常用的命令(一)-------启动、配置等
- 几点建议,让Redis在你的系统中发挥更大作用
- Redis集群进阶-使用集群
- Windows下安装并设置Redis
- redis3 集群简单配置
- redis技术之旅九
- Redis安装与日常使用
- tomcat7和redis的sessoin共享问题处理
- redis 下载安装
- Redis性能问题排查解决手册(七)
- redis持久化RDB和AOF
- redis在linux安装略写
- Redis学习笔记(3)
- Redis介绍
- Redis GEO 特性简介
- redis启动脚本