本文整理汇总了Python中libmc.Client.expire方法的典型用法代码示例。如果您正苦于以下问题:Python Client.expire方法的具体用法?Python Client.expire怎么用?Python Client.expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.expire方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CmemcachedRegressionPrefixCase
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import expire [as 别名]
#.........这里部分代码省略.........
assert raw_mc.get_list(['?%sbar' % self.prefix]) == ['foo']
def test_ketama(self):
mc = Client(
['localhost', 'myhost:11211', '127.0.0.1:11212', 'myhost:11213'])
rs = {
'test:10000': 'localhost:11211',
'test:20000': '127.0.0.1:11212',
'test:30000': '127.0.0.1:11212',
'test:40000': '127.0.0.1:11212',
'test:50000': '127.0.0.1:11212',
'test:60000': 'myhost:11213',
'test:70000': '127.0.0.1:11212',
'test:80000': '127.0.0.1:11212',
'test:90000': '127.0.0.1:11212',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_ketama_with_jocky_alias(self):
mc = Client([
'localhost localhost',
'myhost:11211 myhost',
'127.0.0.1:11212 127.0.0.1:11212',
'myhost:11213 myhost:11213'
])
rs = {
'test:10000': 'localhost',
'test:20000': '127.0.0.1:11212',
'test:30000': '127.0.0.1:11212',
'test:40000': '127.0.0.1:11212',
'test:50000': '127.0.0.1:11212',
'test:60000': 'myhost:11213',
'test:70000': '127.0.0.1:11212',
'test:80000': '127.0.0.1:11212',
'test:90000': '127.0.0.1:11212',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_ketama_with_alias(self):
mc = Client([
'192.168.1.211:11211 tango.mc.douban.com',
'192.168.1.212:11212 uniform.mc.douban.com',
'192.168.1.211:11212 victor.mc.douban.com',
'192.168.1.212:11211 whiskey.mc.douban.com',
])
rs = {
'test:10000': 'whiskey.mc.douban.com',
'test:20000': 'victor.mc.douban.com',
'test:30000': 'victor.mc.douban.com',
'test:40000': 'victor.mc.douban.com',
'test:50000': 'victor.mc.douban.com',
'test:60000': 'uniform.mc.douban.com',
'test:70000': 'tango.mc.douban.com',
'test:80000': 'victor.mc.douban.com',
'test:90000': 'victor.mc.douban.com',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_prefixed_ketama(self):
mc = Client(
['localhost', 'myhost:11211', '127.0.0.1:11212', 'myhost:11213'],
prefix="/prefix"
)
rs = {
'test:10000': '127.0.0.1:11212',
'test:20000': 'localhost:11211',
'test:30000': 'myhost:11213',
'test:40000': 'myhost:11211',
'test:50000': 'myhost:11213',
'test:60000': 'myhost:11213',
'test:70000': 'localhost:11211',
'test:80000': 'myhost:11213',
'test:90000': 'myhost:11213',
}
for k in rs:
self.assertEqual(mc.get_host_by_key(k), rs[k])
def test_should_raise_exception_if_called_in_different_thread(self):
def fn():
self.assertRaises(ThreadUnsafe, self.mc.set, 'key_thread', 1)
# make connection in main thread
self.mc.get('key_thread')
# use it in another thread (should be forbidden)
t = threading.Thread(target=fn)
t.start()
t.join()
def test_expire(self):
self.mc.set('dust', 'cs')
v1 = self.mc.get('dust')
self.mc.expire('dust')
v2 = self.mc.get('dust')
assert v1 == 'cs'
assert v2 is None