本文整理匯總了Python中libmc.Client.get_last_error方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.get_last_error方法的具體用法?Python Client.get_last_error怎麽用?Python Client.get_last_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libmc.Client
的用法示例。
在下文中一共展示了Client.get_last_error方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ErrorCodeTestCase
# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import get_last_error [as 別名]
class ErrorCodeTestCase(unittest.TestCase):
def setUp(self):
self.mc = Client(["127.0.0.1:21211"])
assert self.mc.version()
assert self.mc.get_last_error() == MC_RETURN_OK
def test_invalid_key(self):
self.mc.get('invalid key')
assert self.mc.get_last_error() == MC_RETURN_INVALID_KEY_ERR
def test_mc_server_err(self):
mc = Client(["not_exist_host:11211"])
mc.get('valid_key')
assert mc.get_last_error() == MC_RETURN_MC_SERVER_ERR
示例2: MCStore
# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import get_last_error [as 別名]
class MCStore(object):
def __init__(self, server):
self.server = server
self.mc = Client([server], do_split=0)
def __del__(self):
self.close()
def __repr__(self):
return '<MCStore(server=%s)>' % repr(self.server)
def __str__(self):
return self.server
def set(self, key, data, rev=0):
return bool(self.mc.set(key, data, rev))
def set_raw(self, key, data, rev=0, flag=0): # interface for sync data
if rev < 0:
raise str(rev)
return self.mc.set_raw(key, data, rev, flag)
def get(self, key):
try:
r = self.mc.get(key)
if r is None and self.mc.get_last_error() != 0:
raise IOError(self.mc.get_last_error())
return r
except ValueError:
self.mc.delete(key)
def get_raw(self, key):
r, flag = self.mc.get_raw(key)
if r is None and self.mc.get_last_error() != 0:
raise IOError(
self.mc.get_last_error(), self.mc.get_last_strerror())
return r, flag
def get_multi(self, keys):
return self.mc.get_multi(keys)
def delete(self, key):
return bool(self.mc.delete(key))
def close(self):
if self.mc is not None:
self.mc = None
示例3: test_mc_server_err
# 需要導入模塊: from libmc import Client [as 別名]
# 或者: from libmc.Client import get_last_error [as 別名]
def test_mc_server_err(self):
mc = Client(["not_exist_host:11211"])
mc.get('valid_key')
assert mc.get_last_error() == MC_RETURN_MC_SERVER_ERR