Skip to content

Commit

Permalink
Python: adds ECHO command
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon committed Feb 13, 2024
1 parent 396bb6d commit a777819
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Python, Node: When recieving LPOP/RPOP with count, convert result to Array. ([#811](https:/aws/glide-for-redis/pull/811))
* Python: Added TYPE command ([#945](https:/aws/glide-for-redis/pull/945))
* Python: Added HLEN command ([#944](https:/aws/glide-for-redis/pull/944))
* Python: Added ECHO command ([#953](https:/aws/glide-for-redis/pull/953))

#### Features
* Python, Node: Added support in Lua Scripts ([#775](https:/aws/glide-for-redis/pull/775), [#860](https:/aws/glide-for-redis/pull/860))
Expand Down
1 change: 1 addition & 0 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ enum RequestType {
ZScore = 67;
Type = 68;
HLen = 69;
Echo = 70;
}

message Command {
Expand Down
1 change: 1 addition & 0 deletions glide-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ fn get_command(request: &Command) -> Option<Cmd> {
RequestType::ZScore => Some(cmd("ZSCORE")),
RequestType::Type => Some(cmd("TYPE")),
RequestType::HLen => Some(cmd("HLEN")),
RequestType::Echo => Some(cmd("ECHO")),
}
}

Expand Down
18 changes: 18 additions & 0 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
14 changes: 14 additions & 0 deletions python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions python/python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def transaction_test(
transaction.set(key, value)
transaction.get(key)
transaction.type(key)
transaction.echo(value)

transaction.exists([key])

Expand Down Expand Up @@ -101,6 +102,7 @@ def transaction_test(
OK,
value,
"string",
value,
1,
1,
None,
Expand Down

0 comments on commit a777819

Please sign in to comment.