Пример #1
0
def test_reconnect(cluster):
    with cluster.map() as client:
        for x in range(10):
            client.set(text_type(x), text_type(x))

    with cluster.all() as client:
        client.config_set("timeout", 1)

    time.sleep(2)

    with cluster.map() as client:
        rv = Promise.all([client.get(text_type(x)) for x in range(10)])

    assert rv.value == list(map(text_type, range(10)))
Пример #2
0
 def get_host_for_key(self, key):
     if isinstance(key, text_type):
         k = key.encode("utf-8")
     elif isinstance(key, integer_types):
         k = text_type(key).encode("utf-8")
     else:
         k = bytes_type(key)
     return crc32(k) % len(self.cluster.hosts)
Пример #3
0
def md5_bytes(key):
    if isinstance(key, text_type):
        k = key.encode("utf-8")
    elif isinstance(key, integer_types):
        k = text_type(key).encode("utf-8")
    else:
        k = bytes_type(key)

    return bytearray(hashlib.md5(k).digest())
Пример #4
0
def test_simple_api(cluster, poll, monkeypatch):
    monkeypatch.setattr(clients, "poll", poll)

    client = cluster.get_routing_client()
    with client.map() as map_client:
        for x in range(10):
            map_client.set("key:%s" % x, x)

    for x in range(10):
        assert client.get("key:%d" % x) == text_type(x)