Home > Article > Backend Development > Introduction to the method of using redis under python
Use python to operate the redis database, first download the redis-py module download address https://github.com/andymccurdy/redis-py
and then unzip it Directory, run python setup.py install to install the module
or directly use pip to install
Use:
import redis
r = redis.Redis(host= 'localhost', port=6379, db=0)
r['test'] = 'test' #Or you can set it with r.set('test', 'test') key
r.get('test') #Get the value of test
r.delete('test') #Delete this key
r.flushdb() #Clear the database
r.keys() #List all keys
r.exists('test') #Check whether this key Exists
r.dbsize() #How many entries are there in the database
The above is the detailed content of Introduction to the method of using redis under python. For more information, please follow other related articles on the PHP Chinese website!