Redis 与Python 交互

原创
2017/07/27 18:50
阅读数 244

安装 Redis 模块

1、在线安装

sudo pip3 install redis

2、源码安装

unzip redis-py-master.zip
cd redis-py-master
sudo python setup.py install

Redis 和 Python 交互

导入模块

import redis

链接 Redis

try:
    r=redis.StrictRedis(host='localhost',port=6379)
except Exception,e:
    print e.message

写入数据

form redis import *

r=redis.StrictRedis(host='localhost',port=6379)    # 链接
pipe = r.pipeline()
pipe.set('py10','hello')                           # 创建键值对
pipe.excute()                                      

查数据

temp = r.get('py10')
print(temp)

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
1 收藏
分享
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部