Home >Backend Development >Python Tutorial >Use of redis under python
Use python to operate the redis database, first download the redis-py module download address https://github.com/andymccurdy/redis-py
Run python setup.py install in the decompression directory to install the module
or use pip to install directly
Use:
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r['test'] = 'test' #Or you can r.set('test' , 'test') Set 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 in the database