本文整理汇总了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