加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python中redis的安装和使用

发布时间:2020-12-16 20:08:04 所属栏目:Python 来源:网络整理
导读:python下redis安装 用python操作redis数据库,先下载redis-py模块下载地址https://github.com/andymccurdy/redis-py shell# wget https://github.com/andymccurdy/redis-py 然后解压 在解压目录运行 python setup.py install 安装模块即可 安装完成 使用: i

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() #数据库中多少个条数

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读