Python-使用python-memcache操作Memcached
生活随笔
收集整理的這篇文章主要介紹了
Python-使用python-memcache操作Memcached
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
?
預備
-
Python 2.7
-
Memcached 1.4.x
-
python-memcached-1.54
安裝
1、下載源碼包。
wget http://ftp.tummy.com/pub/python-memcached/old-releases/python-memcached-1.54.tar.gz2、解壓縮。
tar -zxvf python-memcached-1.54.tar.gz3、安裝。
python setup.py install注:需要root權限
編程
#coding:utf8import memcacheclass MemcachedClient():''' python memcached 客戶端操作示例 '''def __init__(self, hostList):self.__mc = memcache.Client(hostList); def set(self, key, value):result = self.__mc.set("name", "NieYong") return result def get(self, key):name = self.__mc.get("name") return name def delete(self, key):result = self.__mc.delete("name") return resultif __name__ == '__main__':mc = MemcachedClient(["127.0.0.1:11511", "127.0.0.1:11512"])key = "name"result = mc.set(key, "NieYong") print "set的結果:", resultname = mc.get(key) print "get的結果:", nameresult = mc.delete(key) print "delete的結果:", result執行腳本的結果:
set的結果: True get的結果: NieYong delete的結果: 1轉載于:https://my.oschina.net/sharesuiyue/blog/789001
總結
以上是生活随笔為你收集整理的Python-使用python-memcache操作Memcached的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Uva 10562 看图写树
- 下一篇: 51CTO学院双十一营收400万,预测I