import asyncio import pytest import sys import logging from aioredis import RedisError, ReplyError, PoolClosedError from aioredis.errors import MasterReplyError from aioredis.sentinel.commands import RedisSentinel from aioredis.abc import AbcPool from _testutils import redis_version pytestmark = redis_version(2, 8, 12, reason="Sentinel v2 required") if sys.platform == 'win32': pytestmark = pytest.mark.skip(reason="unstable on windows") BPO_30399 = sys.version_info >= (3, 7, 0, 'alpha', 3) async 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 (await redis_sentinel.ping()) != b'PONG' await redis_sentinel.wait_closed() async def test_ping(redis_sentinel):
import pytest import asyncio from collections import OrderedDict from unittest import mock from aioredis.errors import BusyGroupError from _testutils import redis_version pytestmark = redis_version( 5, 0, 0, reason="Streams only available since Redis 5.0.0") @asyncio.coroutine async def add_message_with_sleep(redis, loop, stream, fields): await asyncio.sleep(0.2, loop=loop) result = await redis.xadd(stream, fields) return result @pytest.mark.run_loop async def test_xadd(redis, server_bin): fields = OrderedDict(( (b'field1', b'value1'), (b'field2', b'value2'), )) message_id = await redis.xadd('test_stream', fields) # Check the result is in the expected format (i.e: 1507400517949-0) assert b'-' in message_id timestamp, sequence = message_id.split(b'-')
import pytest import asyncio from collections import OrderedDict from unittest import mock from aioredis.errors import BusyGroupError from _testutils import redis_version pytestmark = redis_version(5, 0, 0, reason="Streams only available since Redis 5.0.0") @asyncio.coroutine async def add_message_with_sleep(redis, loop, stream, fields): await asyncio.sleep(0.2, loop=loop) result = await redis.xadd(stream, fields) return result @pytest.mark.run_loop async def test_xadd(redis, server_bin): fields = OrderedDict(( (b'field1', b'value1'), (b'field2', b'value2'), )) message_id = await redis.xadd('test_stream', fields) # Check the result is in the expected format (i.e: 1507400517949-0)
import pytest import asyncio import sys from aioredis import ( SlaveNotFoundError, ReadOnlyError, ) from _testutils import redis_version pytestmark = 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)
import pytest from _testutils import redis_version pytestmark = 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