async_memcache for tornado

來源:互聯網
上載者:User

tornado 是一個純python 實現的非阻塞web伺服器,內建了非同步httpclient,可以非同步請求http網路資源。

在實際應用中,我們常常需要訪問memcached等資源,發現官方並沒有具體實現memcache非同步用戶端,但是tornado留出了ioloop讓我們很容易就可以實現非同步socket網路訪問。
於是參照memcache的通訊協定,我簡單實現了一個非同步socket的memcache用戶端。

使用樣本

原始碼下載: async_memcache.py

if __name__ == '__main__':    client = MemcacheClient('localhost', 11211)    def get_callback(val):        print val    client.set('hello', 'world', get_callback)    client.set('hello3', 'world3', get_callback)    client.get('hello3', get_callback)    client.get('hello2', get_callback)    client.get(['hello', 'hello2', 'hello3'], get_callback)    client.set('hello4', 'abc', get_callback)    client.get('hello4', get_callback)    client.append('hello4', 'append', get_callback)    client.get('hello4', get_callback)    client.prepend('hello4', 'prepend', get_callback)    client.get('hello4', get_callback)    client.delete('hello4', get_callback)    client.get('hello4', get_callback)    client.delete('hello4', get_callback)    IOLoop.instance().start()

希望對你有用 ^_^

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.