本文整理汇总了Python中libmc.Client.get_realtime_host_by_key方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_realtime_host_by_key方法的具体用法?Python Client.get_realtime_host_by_key怎么用?Python Client.get_realtime_host_by_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmc.Client
的用法示例。
在下文中一共展示了Client.get_realtime_host_by_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_realtime_host_w_failover
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_realtime_host_by_key [as 别名]
def test_realtime_host_w_failover(self):
servers = ["127.0.0.1:21211", "127.0.0.1:21212"]
mc = Client(servers)
failover_mc = Client(servers, failover=True)
hosts_visited = set()
for i in range(1000):
key = "test:realtime:route:%d" % i
h1 = mc.get_host_by_key(key)
h2 = mc.get_realtime_host_by_key(key)
assert h1 is not None
assert h1 == h2
h3 = failover_mc.get_host_by_key(key)
h4 = failover_mc.get_realtime_host_by_key(key)
assert h3 == h1
assert h4 == h1
hosts_visited.add(h1)
assert len(hosts_visited) == len(servers)
示例2: test_none_host
# 需要导入模块: from libmc import Client [as 别名]
# 或者: from libmc.Client import get_realtime_host_by_key [as 别名]
def test_none_host(self):
existed_server = "127.0.0.1:21211"
not_existed_server = "127.0.0.1:1"
servers = [existed_server, not_existed_server]
mc = Client(servers)
failover_mc = Client(servers, failover=True)
hosts_visited = set()
for i in range(1000):
key = "test:realtime:route:%d" % i
h1 = mc.get_host_by_key(key)
h2 = mc.get_realtime_host_by_key(key)
if h1 == existed_server:
assert h1 == h2
elif h1 == not_existed_server:
assert h2 is None
h3 = failover_mc.get_host_by_key(key)
h4 = failover_mc.get_realtime_host_by_key(key)
assert h3 == h1
assert h4 == existed_server
hosts_visited.add(h1)
assert len(hosts_visited) == len(servers)