Redis installation under python
Use python to operate the redis database, first download the redis-py module download address https://github.com/andymccurdy/redis-py
shell# wget <a href="https://github.com/andymccurdy/redis-py" target="_blank">https://github.com/andymccurdy/redis-py[/code]
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() #数据库中多少个条数
The above is the detailed content of Introduction to the installation and use of redis in python. For more information, please follow other related articles on the PHP Chinese website!