Home >Backend Development >Python Tutorial >Installation and use of redis under python

Installation and use of redis under python

高洛峰
高洛峰Original
2016-10-19 09:16:451749browse

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 https://github.com/andymccurdy/redis -py


Then unzip

In the unzipped directory, run python setup.py install to install the module

The installation is complete

Use:

import redis

r = redis.Redis(host ='localhost', port=6379, db=0)

r['test'] = 'test' #Or you can r.set('test', 'test') to set the key

r. get('test') #Get the value of test

r.delete('test') #Delete this key

r.flushdb() #Clear the database

r.keys() #Column Out all keys

r.exists('test') #Check whether this key exists

r.dbsize() #How many entries in the database


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn