python下redis的使用
來源:懂視網
責編:小采
時間:2020-11-27 14:28:17
python下redis的使用
python下redis的使用:用python操作redis數據庫,先下載redis-py模塊下載地址https://github.com/andymccurdy/redis-py在解壓目錄運行 python setup.py install安裝模塊或者直接使用pip安裝使用:import redisr = redis.Redis(host=local
導讀python下redis的使用:用python操作redis數據庫,先下載redis-py模塊下載地址https://github.com/andymccurdy/redis-py在解壓目錄運行 python setup.py install安裝模塊或者直接使用pip安裝使用:import redisr = redis.Redis(host=local

用python操作redis數據庫,先下載redis-py模塊下載地址https://github.com/andymccurdy/redis-py
在解壓目錄運行 python setup.py install安裝模塊
或者直接使用pip安裝
使用:
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() #數據庫中多少個條數
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
python下redis的使用
python下redis的使用:用python操作redis數據庫,先下載redis-py模塊下載地址https://github.com/andymccurdy/redis-py在解壓目錄運行 python setup.py install安裝模塊或者直接使用pip安裝使用:import redisr = redis.Redis(host=local