本文整理匯總了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