本文整理汇总了Python中umemcache.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testStats
def testStats(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
d = c.stats()
self.assertTrue (d.has_key("uptime"))
self.assertTrue (d.has_key("bytes"))
示例2: testVersion
def testVersion(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
v = c.version()
l = v.split('.');
self.assertEquals(3, len(l))
示例3: testTupleRefCrashFix
def testTupleRefCrashFix(self):
client = Client(MEMCACHED_ADDRESS)
for i in range(1000):
try:
client.connect()
except:
pass
示例4: testCas
def testCas(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
c.set("key1", "a")
value, flags, cas = c.gets("key1")
self.assertEquals("STORED", c.cas("key1", "b", cas))
c.set("key1", "a")
self.assertEquals("EXISTS", c.cas("key1", "b", cas))
示例5: _create_connector
def _create_connector(self):
if self.max_item_size is not None:
self._client = OriginalClient(self.address, self.max_item_size)
else:
self._client = OriginalClient(self.address)
self.funcs = [func for func in dir(self._client)
if not func.startswith('_')]
示例6: testOversizedKey
def testOversizedKey(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
data = "A" * (1000 * 1000 * 2)
try:
r = c.set("test", data)
assert False
except(RuntimeError):
pass
示例7: testConnectFails
def testConnectFails(self):
c = Client("130.244.1.1:31337");
try:
c.connect();
assert False
except:
pass
c.disconnect();
pass
示例8: testConnectDNSFails
def testConnectDNSFails(self):
c = Client("flensost:12111");
try:
c.connect();
assert False
except:
pass
c.disconnect();
pass
示例9: testFlushAll
def testFlushAll(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
c.set("key1", "31337")
self.assertEquals(c.get("key1")[0], "31337")
c.flush_all()
self.assertEquals(c.get("key1"), None)
示例10: testConnectFails
def testConnectFails(self):
c = Client("130.244.1.1:31337");
c.sock.settimeout(2)
try:
c.connect();
assert False
except:
pass
c.disconnect();
pass
示例11: testPipelineDoesNotAllowReads
def testPipelineDoesNotAllowReads(self):
c = Client(MEMCACHED_ADDRESS)
c.connect()
c.begin_pipeline()
self.assertRaises(MemcachedError, c.get, "foo")
self.assertRaises(MemcachedError, c.gets, "foo")
self.assertRaises(MemcachedError, c.get_multi, ["foo"])
self.assertRaises(MemcachedError, c.gets_multi, ["foo"])
self.assertRaises(MemcachedError, c.version)
self.assertRaises(MemcachedError, c.stats)
示例12: Client
class Client(object):
"""On connection errors, tries to reconnect
"""
def __init__(self, address, max_item_size=None, max_connect_retries=5,
reconnect_delay=.5):
self.address = address
self.max_item_size = max_item_size
self._client = None
self.funcs = []
self._create_client()
self.max_connect_retries = max_connect_retries
self.reconnect_delay = reconnect_delay
def _create_connector(self):
if self.max_item_size is not None:
self._client = OriginalClient(self.address, self.max_item_size)
else:
self._client = OriginalClient(self.address)
self.funcs = [func for func in dir(self._client)
if not func.startswith('_')]
def _create_client(self):
reconnect = self._client is not None
if reconnect:
try:
self._client.close()
except Exception:
pass
self._create_connector()
if reconnect:
retries = 0
delay = self.reconnect_delay
while retries < self.max_connect_retries:
try:
self._client.connect()
except socket.error, exc:
if exc.errno == EISCONN:
return # we're good
if exc.errno == EINVAL:
# we're doomed, retry
self._create_connector()
time.sleep(delay)
retries += 1
delay *= 2 # growing the delay
raise exc
示例13: testDel
def testDel(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
c.set("key1", "a")
c.delete("key1")
self.assertEquals(None, c.get("key1"))
pass
示例14: testGets
def testGets(self):
c = Client(MEMCACHED_ADDRESS);
c.connect();
c.set("key", "value")
self.assertEquals("value", c.gets("key")[0])
self.assertEquals(None, c.gets("key23123"))
r = c.gets("key")
self.assertEquals(3, len(r))
pass
示例15: testAppend
def testAppend(self):
c = Client(MEMCACHED_ADDRESS)
c.connect()
c.set("key1", "a")
self.assertEquals("STORED", c.append("key1", "b"))
self.assertEquals("ab", c.get("key1")[0])
pass