Exemplo n.º 1
0
def test_cache_cluster_batch_mode(redis_hosts):
    cache = CacheCluster(redis_hosts)

    @cache.cache()
    def cluster_batch_test_func(value):
        return value

    for i in range(5):
        assert cluster_batch_test_func(i) == i

    results = []
    with cache.batch_mode():
        for i in range(10):
            rv = cluster_batch_test_func(i)
            assert rv.is_pending
            assert rv.value is None
            results.append(rv)
    for i, rv in enumerate(results):
        assert rv.is_resolved
        assert rv.value == i

    for i in range(20):
        assert cluster_batch_test_func(i) == i
Exemplo n.º 2
0
def test_cache_cluster_batch_mode(redis_hosts):
    cache = CacheCluster(redis_hosts)

    @cache.cache()
    def cluster_batch_test_func(value):
        return value

    for i in range(5):
        assert cluster_batch_test_func(i) == i

    results = []
    with cache.batch_mode():
        for i in range(10):
            rv = cluster_batch_test_func(i)
            assert rv.is_pending
            assert rv.value is None
            results.append(rv)
    for i, rv in enumerate(results):
        assert rv.is_resolved
        assert rv.value == i

    for i in range(20):
        assert cluster_batch_test_func(i) == i
Exemplo n.º 3
0
def test_cache_cluster_namespace(redis_hosts):
    cache01 = CacheCluster(redis_hosts)
    cache02 = CacheCluster(redis_hosts, namespace='test:')
    assert cache01.set('key', 'value')
    assert cache01.get('key') == 'value'
    assert cache02.get('key') is None
Exemplo n.º 4
0
def test_cache_cluster_basic_apis(redis_hosts):
    cache = CacheCluster(redis_hosts)
    assert cache.get('key') is None
    assert cache.set('key', 'value')
    assert cache.get('key') == 'value'
    assert cache.delete('key')
    assert cache.get('key') is None

    assert cache.get_many('key1', 'key2') == [None, None]
    assert cache.set_many({'key1': 'value1', 'key2': 'value2'})
    assert cache.get_many('key1', 'key2') == ['value1', 'value2']
    assert cache.delete_many('key1', 'key2')
    assert cache.get_many('key1', 'key2') == [None, None]
    assert cache.get_many() == []
    assert cache.set_many({})
    assert cache.delete_many()

    assert cache.get('key') is None
    assert cache.set('key', ['value'])
    assert cache.get('key') == ['value']
    assert cache.delete('key')
    assert cache.get('key') is None
Exemplo n.º 5
0
def test_cache_cluster_namespace(redis_hosts):
    cache01 = CacheCluster(redis_hosts)
    cache02 = CacheCluster(redis_hosts, namespace='test:')
    assert cache01.set('key', 'value')
    assert cache01.get('key') == 'value'
    assert cache02.get('key') is None
Exemplo n.º 6
0
def test_cache_cluster_basic_apis(redis_hosts):
    cache = CacheCluster(redis_hosts)
    assert cache.get('key') is None
    assert cache.set('key', 'value')
    assert cache.get('key') == 'value'
    assert cache.delete('key')
    assert cache.get('key') is None

    assert cache.get_many('key1', 'key2') == [None, None]
    assert cache.set_many({'key1': 'value1', 'key2': 'value2'})
    assert cache.get_many('key1', 'key2') == ['value1', 'value2']
    assert cache.delete_many('key1', 'key2')
    assert cache.get_many('key1', 'key2') == [None, None]
    assert cache.get_many() == []
    assert cache.set_many({})
    assert cache.delete_many()

    assert cache.get('key') is None
    assert cache.set('key', ['value'])
    assert cache.get('key') == ['value']
    assert cache.delete('key')
    assert cache.get('key') is None