當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.get_realtime_host_by_key方法代碼示例

本文整理匯總了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)
開發者ID:douban,項目名稱:libmc,代碼行數:20,代碼來源:test_router.py

示例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)
開發者ID:douban,項目名稱:libmc,代碼行數:25,代碼來源:test_router.py


注:本文中的libmc.Client.get_realtime_host_by_key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。