您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页python下redis安装和使用

python下redis安装和使用

来源:爱go旅游网

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

Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务