cunla / fakeredis-py

Implementation of Redis in python without having a Redis server running. Fully compatible with using redis-py.
https://fakeredis.moransoftware.ca/
BSD 3-Clause "New" or "Revised" License
298 stars 48 forks source link

TYPE command is not working for stream type #226

Closed GTVanitha closed 1 year ago

GTVanitha commented 1 year ago

Code key_type = await redis_client.type(key)

Error

env/lib/python3.10/site-packages/redis/asyncio/client.py:518: in execute_command
    return await conn.retry.call_with_retry(
env/lib/python3.10/site-packages/redis/asyncio/retry.py:59: in call_with_retry
    return await do()
env/lib/python3.10/site-packages/redis/asyncio/client.py:491: in _send_command_parse_response
    await conn.send_command(*args)
env/lib/python3.10/site-packages/redis/asyncio/connection.py:752: in send_command
    await self.send_packed_command(
env/lib/python3.10/site-packages/redis/asyncio/connection.py:727: in send_packed_command
    self._writer.writelines(command)
env/lib/python3.10/site-packages/fakeredis/aioredis.py:99: in writelines
    self._socket.sendall(chunk)
env/lib/python3.10/site-packages/fakeredis/_basefakesocket.py:217: in sendall
    self._parser.send(data)
env/lib/python3.10/site-packages/fakeredis/_basefakesocket.py:135: in _parse_commands
    self._process_command(fields)
env/lib/python3.10/site-packages/fakeredis/_basefakesocket.py:245: in _process_command
    result = self._run_command(func, sig, cmd_arguments, False)
env/lib/python3.10/site-packages/fakeredis/_basefakesocket.py:149: in _run_command
    result = func(*args)
env/lib/python3.10/site-packages/fakeredis/commands_mixins/generic_mixin.py:259: in type
    return key_value_type(key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

key = <fakeredis._commands.CommandItem object at 0x7f26d79d7bb0>

    def key_value_type(key):
        if key.value is None:
            return SimpleString(b'none')
        elif isinstance(key.value, bytes):
            return SimpleString(b'string')
        elif isinstance(key.value, list):
            return SimpleString(b'list')
        elif isinstance(key.value, set):
            return SimpleString(b'set')
        elif isinstance(key.value, ZSet):
            return SimpleString(b'zset')
        elif isinstance(key.value, dict):
            return SimpleString(b'hash')
        else:
>           assert False  # pragma: nocover
E           AssertionError

env/lib/python3.10/site-packages/fakeredis/_commands.py:451: AssertionError

Env

danielm-cfa commented 1 year ago

Can you provide the full code creating this error? I created this test to check and everything seems to pass:

async def test_type(req_aioredis2: redis.asyncio.Redis):
    r = req_aioredis2
    await r.set('string_key', "value")
    await r.lpush("list_key", "value")
    await r.sadd("set_key", "value")
    await r.zadd("zset_key", {"value": 1})
    await r.hset('hset_key', 'key', 'value')

    assert b'string' == await r.type('string_key')  # noqa: E721
    assert b'list' == await r.type('list_key')  # noqa: E721
    assert b'set' == await r.type('set_key')  # noqa: E721
    assert b'zset' == await r.type('zset_key')  # noqa: E721
    assert b'hash' == await r.type('hset_key')  # noqa: E721
    assert b'none' == await  r.type('none_key')  # noqa: E721
cunla commented 1 year ago

Closing due to no response.

GTVanitha commented 1 year ago

Apologies for the delayed response. I'm currently storing data in a Redis stream, and before processing the data within the stream, I'm checking whether the key's data type is of the 'stream' type.

According to the Redis official documentation, the 'TYPE' command supports data types such as string, list, set, zset, hash, and stream. However, it appears that fakeredis does not support the 'stream' data type, leading to the reported error.

Additionally, in the mentioned test case, there is no check for the 'stream' data type.

cunla commented 1 year ago

This has been fixed in the latest version: https://github.com/cunla/fakeredis-py/releases/tag/v2.18.1

GTVanitha commented 1 year ago

Thank you