开心六月综合激情婷婷|欧美精品成人动漫二区|国产中文字幕综合色|亚洲人在线成视频

    1. 
      
        <b id="zqfy3"><legend id="zqfy3"><fieldset id="zqfy3"></fieldset></legend></b>
          <ul id="zqfy3"></ul>
          <blockquote id="zqfy3"><strong id="zqfy3"><dfn id="zqfy3"></dfn></strong></blockquote>
          <blockquote id="zqfy3"><legend id="zqfy3"></legend></blockquote>
          打開APP
          userphoto
          未登錄

          開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

          開通VIP
          Redis的Python客戶端redis-py

          Redis的Python客戶端redis-py

          分類: Python NoSQL 6280人閱讀 評論(1) 收藏 舉報(bào)

          1. 安裝

          1. redis-py
                  a. 使用easy_install
          1. sudo easy_install redis  

                  b. 源碼安裝
          1. git clone https://github.com/andymccurdy/redis-py.git  
          2. cd redis-py  
          3. python setup.py install  

          2. Parser安裝
                  Parser可以控制如何解析redis響應(yīng)的內(nèi)容。redis-py包含兩個(gè)Parser類,PythonParser和HiredisParser。默認(rèn),如果已經(jīng)安裝了hiredis模塊,redis-py會使用HiredisParser,否則會使用PythonParser。
          HiredisParser是C編寫的,由redis核心團(tuán)隊(duì)維護(hù),性能要比PythonParser提高10倍以上,所以推薦使用。安裝方法,使用easy_install:
          1. easy_install hiredis  

          2. 使用

                  redis-py提供兩個(gè)類Redis和StrictRedis用于實(shí)現(xiàn)Redis的命令,StrictRedis用于實(shí)現(xiàn)大部分官方的命令,并使用官方的語法和命令(比如,SET命令對應(yīng)與StrictRedis.set方法)。Redis是StrictRedis的子類,用于向后兼容舊版本的redis-py。
          1. import redis  
          2.   
          3. r = redis.StrictRedis(host='127.0.0.1', port=9212)  
          4. r.set('foo''hello')  
          5. r.rpush('mylist''one')  
          6. print r.get('foo')  
          7. print r.rpop('mylist')  
                  redis-py使用connection pool來管理對一個(gè)redis server的所有連接,避免每次建立、釋放連接的開銷。默認(rèn),每個(gè)Redis實(shí)例都會維護(hù)一個(gè)自己的連接池??梢灾苯咏⒁粋€(gè)連接池,然后作為參數(shù)Redis,這樣就可以實(shí)現(xiàn)多個(gè)Redis實(shí)例共享一個(gè)連接池。
          1. import redis  
          2.   
          3. pool = redis.ConnectionPool(host='127.0.0.1', port=9212)  
          4. r = redis.Redis(connection_pool=pool)  
          5. r.set('one''first')  
          6. r.set('two''second')  
          7. print r.get('one')  
          8. print r.get('two')  
                  redis pipeline機(jī)制,可以在一次請求中執(zhí)行多個(gè)命令,這樣避免了多次的往返時(shí)延。
          1. import redis  
          2.   
          3. pool = redis.ConnectionPool(host='127.0.0.1', port=9212)  
          4. r = redis.Redis(connection_pool=pool)  
          5. pipe = r.pipeline()  
          6. pipe.set('one''first')  
          7. pipe.set('two''second')  
          8. pipe.execute()  
          9.   
          10. pipe.set('one''first').rpush('list''hello').rpush('list''world').execute()  
                  redis-py默認(rèn)在一次pipeline中的操作是原子的,要改變這種方式,可以傳入transaction=False,
          1. pipe = r.pipeline(transaction=False
          本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
          打開APP,閱讀全文并永久保存 查看更多類似文章
          猜你喜歡
          類似文章
          Python gevent + zmq + redis 搭配小實(shí)踐 | kaka
          python筆記67 - python 連接 redis
          python如何安裝pip和easy_install
          安裝Redis Live監(jiān)控服務(wù)
          Python爬蟲代理池分享——再也不怕反爬蟲
          Python操作redis
          更多類似文章 >>
          生活服務(wù)
          分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
          綁定賬號成功
          后續(xù)可登錄賬號暢享VIP特權(quán)!
          如果VIP功能使用有故障,
          可點(diǎn)擊這里聯(lián)系客服!

          聯(lián)系客服