import pytest import asyncio from collections import OrderedDict from unittest import mock from aioredis.commands.streams import parse_messages from aioredis.errors import BusyGroupError from tests.testutils import redis_version pytestmark = redis_version(5, 0, 0, reason="Streams only available since Redis 5.0.0") async def add_message_with_sleep(redis, stream, fields): await asyncio.sleep(0.2) result = await redis.xadd(stream, fields) return result @pytest.mark.asyncio 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 asyncio import logging import sys import pytest from aioredis import PoolClosedError, RedisError, ReplyError from aioredis.abc import AbcPool from aioredis.errors import MasterReplyError from aioredis.sentinel.commands import RedisSentinel from tests.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) @pytest.mark.asyncio 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()
import pytest from tests.testutils import redis_version pytestmark = redis_version(2, 8, 9, reason="HyperLogLog works only with redis>=2.8.9") @pytest.mark.asyncio 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