diff --git a/CHANGELOG.md b/CHANGELOG.md index 0881bb1013..7ce7235c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Python, Node: When recieving LPOP/RPOP with count, convert result to Array. ([#811](https://github.com/aws/glide-for-redis/pull/811)) * Python: Added TYPE command ([#945](https://github.com/aws/glide-for-redis/pull/945)) * Python: Added HLEN command ([#944](https://github.com/aws/glide-for-redis/pull/944)) +* Python: Added ECHO command ([#953](https://github.com/aws/glide-for-redis/pull/953)) #### Features * Python, Node: Added support in Lua Scripts ([#775](https://github.com/aws/glide-for-redis/pull/775), [#860](https://github.com/aws/glide-for-redis/pull/860)) diff --git a/glide-core/src/protobuf/redis_request.proto b/glide-core/src/protobuf/redis_request.proto index 244aefbb86..0de865f2e4 100644 --- a/glide-core/src/protobuf/redis_request.proto +++ b/glide-core/src/protobuf/redis_request.proto @@ -105,6 +105,7 @@ enum RequestType { ZScore = 67; Type = 68; HLen = 69; + Echo = 70; } message Command { diff --git a/glide-core/src/socket_listener.rs b/glide-core/src/socket_listener.rs index 481a07ec80..7c8a23968a 100644 --- a/glide-core/src/socket_listener.rs +++ b/glide-core/src/socket_listener.rs @@ -348,6 +348,7 @@ fn get_command(request: &Command) -> Option { RequestType::ZScore => Some(cmd("ZSCORE")), RequestType::Type => Some(cmd("TYPE")), RequestType::HLen => Some(cmd("HLEN")), + RequestType::Echo => Some(cmd("ECHO")), } } diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 752bb5f17f..bd2f98ab39 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1121,6 +1121,24 @@ async def ttl(self, key: str) -> int: """ return cast(int, await self._execute_command(RequestType.TTL, [key])) + async def echo(self, message: str) -> str: + """ + Returns `message`. + + See https://redis.io/commands/echo for more details. + + Args: + message (str): The message to be echoed back. + + Returns: + str: The `message` sent as an argument. + + Examples: + >>> await client.echo("Glide-for-Redis") + 'Glide-for-Redis' + """ + return cast(str, await self._execute_command(RequestType.Echo, [message])) + async def type(self, key: str) -> str: """ Returns the string representation of the type of the value stored at `key`. diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index d7b9b5262d..e284f85b81 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -818,6 +818,20 @@ def ttl(self, key: str): """ self.append_command(RequestType.TTL, [key]) + def echo(self, message: str): + """ + Returns `message`. + + See https://redis.io/commands/echo for more details. + + Args: + message (str): The message to be echoed back. + + Commands response: + str: The `message` sent as an argument. + """ + self.append_command(RequestType.Echo, [message]) + def type(self, key: str): """ Returns the string representation of the type of the value stored at `key`. diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 290613e453..a90f2e9f89 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -1223,6 +1223,11 @@ async def test_type(self, redis_client: TRedisClient): assert (await redis_client.type(key)).lower() == "none" + @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) + async def test_echo(self, redis_client: TRedisClient): + message = get_random_string(5) + assert await redis_client.echo(message) == message class TestCommandsUnitTests: def test_expiry_cmd_args(self): diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 35bd6b68c2..a5eccf8fab 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -36,6 +36,7 @@ def transaction_test( transaction.set(key, value) transaction.get(key) transaction.type(key) + transaction.echo(value) transaction.exists([key]) @@ -101,6 +102,7 @@ def transaction_test( OK, value, "string", + value, 1, 1, None,