python下redis安装和使用

来源:互联网 发布:arm linux启动进度条 编辑:程序博客网 时间:2024/06/09 12:08

python下redis安装和使用

2012-12-20 22:41:57   来源:   评论:0 点击:835
python下redis安装用python操作redis数据库,先下载redis-py模块下载地址https://github.com/andymccurdy/redis-pyshell# wgethttps://git...
python下redis安装

用python操作redis数据库,先下载redis-py模块下载地址https://github.com/andymccurdy/redis-py

shell# wget https://github.com/andymccurdy/redis-py

然后解压
 
在解压目录运行 python setup.py install安装模块即可

安装完成
 
使用:
 
import redis
 
r = redis.Redis(host=’localhost’, port=6379, db=0)
 
r['test'] = ‘test’ #或者可以r.set(‘test’, ‘test’) 设置key
 
r.get(‘test’)  #获取test的值
 
r.delete(‘test’) #删除这个key
 
r.flushdb() #清空数据库
 
r.keys() #列出所有key
 
r.exists(‘test’) #检测这个key是否存在
 
r.dbsize() #数据库中多少个条数

相关热词搜索:python redis 安装

0 0