redis -- python操作串連redis__python

來源:互聯網
上載者:User

1.先安裝 redis,pyredis

sudo pip install redis  

sudo pip install python-redis


2.樣本:

import redis >>> r = redis . Redis ( host = 'localhost' , port = 6379 , db = 0 ) >>> r . set ( 'guo' , 'shuai' ) True >>> r . get ( 'guo' ) 'shuai' >>> r [ 'guo' ]              'shuai' >>> r . keys ( ) [ 'guo' ] >>> r . dbsize ( )          #當前資料庫包含多少條資料       1L >>> r . delete ( 'guo' ) 1 >>> r . save ( )                #執行“檢查點”操作,將資料寫回磁碟。儲存時阻塞 True >>> r . get ( 'guo' ) ; >>> r . flushdb ( )          #清空r中的所有資料 True


3.管道:

server和client之間是利用socket發送tcp報文進行通訊的,利用pipeline的方式從client打包多條命令一起發出,不需要等待單條命令的響應返回,而redis服務端會處理完多條命令後會將多條命令的處理結果打包到一起返回給用戶端。這樣就能節省浪費在網路延遲上的時間, pipeline方式打包命令發送,

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.