import pytest pytestmark = pytest.redis_version( 2, 8, 9, reason='HyperLogLog works only with redis>=2.8.9') @pytest.mark.run_loop async def test_pfcount(redis): key = 'hll_pfcount' other_key = 'some-other-hll' # add initial data, cardinality changed so command returns 1 is_changed = await redis.pfadd(key, 'foo', 'bar', 'zap') assert is_changed == 1 # add more data, cardinality not changed so command returns 0 is_changed = await redis.pfadd(key, 'zap', 'zap', 'zap') assert is_changed == 0 # add event more data, cardinality not changed so command returns 0 is_changed = await redis.pfadd(key, 'foo', 'bar') assert is_changed == 0 # check cardinality of one key cardinality = await redis.pfcount(key) assert cardinality == 3 # create new key (variable) for cardinality estimation is_changed = await redis.pfadd(other_key, 1, 2, 3) assert is_changed == 1
import asyncio import pytest import sys from aioredis import RedisError, ReplyError, PoolClosedError from aioredis.sentinel.commands import RedisSentinel pytestmark = pytest.redis_version(2, 8, 12, reason="Sentinel v2 required") if sys.platform == 'win32': pytestmark = pytest.mark.skip(reason="unstable on windows") @pytest.mark.run_loop def test_client_close(redis_sentinel): assert isinstance(redis_sentinel, RedisSentinel) assert not redis_sentinel.closed redis_sentinel.close() assert redis_sentinel.closed with pytest.raises(PoolClosedError): assert (yield from redis_sentinel.ping()) != b'PONG' yield from redis_sentinel.wait_closed() @pytest.mark.run_loop def test_global_loop(sentinel, create_sentinel, loop): asyncio.set_event_loop(loop) # force global loop client = yield from create_sentinel([sentinel.tcp_address], loop=None)
attempts_count = 0 while attempts_count < attempts: try: return await func(**kwargs) except AssertionError: if attempts_count >= attempts: raise attempts_count += 1 await asyncio.sleep(sleep_time) assert False cluster_test = pytest.redis_version( 3, 0, 0, reason='Cluster support was added in version 3') def test_parse_moved_response_error(): assert parse_moved_response_error(ReplyError('')) is None assert parse_moved_response_error(ReplyError('ASK')) is None assert parse_moved_response_error( ReplyError('MOVED 3999 127.0.0.1:6381')) == ('127.0.0.1', 6381) def test_nodes_ok_info_parse(): data = list(parse_cluster_nodes(RAW_NODE_INFO_DATA_OK)) assert data == NODE_INFO_DATA_OK def test_nodes_fail_info_parse():
attempts_count = 0 while attempts_count < attempts: try: return await func(**kwargs) except AssertionError: if attempts_count >= attempts: raise attempts_count += 1 await asyncio.sleep(sleep_time) assert False cluster_test = pytest.redis_version( 3, 0, 0, reason='Cluster support was added in version 3') def test_parse_moved_response_error(): assert parse_moved_response_error(ReplyError('')) is None assert parse_moved_response_error(ReplyError('ASK')) is None assert parse_moved_response_error( ReplyError('MOVED 3999 127.0.0.1:6381') ) == ('127.0.0.1', 6381) def test_nodes_ok_info_parse(): data = list(parse_cluster_nodes(RAW_NODE_INFO_DATA_OK)) assert data == NODE_INFO_DATA_OK
import pytest import asyncio import sys from aioredis import ( SlaveNotFoundError, ReadOnlyError, ) pytestmark = pytest.redis_version(2, 8, 12, reason="Sentinel v2 required") if sys.platform == 'win32': pytestmark = pytest.mark.skip(reason="unstable on windows") @pytest.mark.xfail @pytest.mark.run_loop(timeout=40) async def test_auto_failover(start_sentinel, start_server, create_sentinel, create_connection, loop): server1 = start_server('master-failover', ['slave-read-only yes']) start_server('slave-failover1', ['slave-read-only yes'], slaveof=server1) start_server('slave-failover2', ['slave-read-only yes'], slaveof=server1) sentinel1 = start_sentinel('sentinel-failover1', server1, quorum=2) sentinel2 = start_sentinel('sentinel-failover2', server1, quorum=2) sp = await create_sentinel([sentinel1.tcp_address, sentinel2.tcp_address], timeout=1) _, old_port = await sp.master_address(server1.name)