From 7a394d95d825bcab75986a7631b379112505559f Mon Sep 17 00:00:00 2001 From: GilboaAWS Date: Wed, 3 Jul 2024 08:48:12 +0000 Subject: [PATCH] Changed to bytes --- glide-core/src/protobuf/redis_request.proto | 1 - glide-core/src/request_type.rs | 1 - .../glide/async_commands/cluster_commands.py | 16 ++++++------ .../async_commands/standalone_commands.py | 26 +++++++++---------- .../glide/async_commands/transaction.py | 20 +++++++------- python/python/tests/test_async_client.py | 18 ++++++------- python/python/tests/test_transaction.py | 4 +-- 7 files changed, 42 insertions(+), 44 deletions(-) diff --git a/glide-core/src/protobuf/redis_request.proto b/glide-core/src/protobuf/redis_request.proto index af093b4769..d0c0e5d5a1 100644 --- a/glide-core/src/protobuf/redis_request.proto +++ b/glide-core/src/protobuf/redis_request.proto @@ -216,7 +216,6 @@ enum RequestType { Move = 174; SInterCard = 175; XRevRange = 176; - SortReadOnly = 177; Copy = 178; MSetNX = 179; LPos = 180; diff --git a/glide-core/src/request_type.rs b/glide-core/src/request_type.rs index 4881241e1a..7da4898821 100644 --- a/glide-core/src/request_type.rs +++ b/glide-core/src/request_type.rs @@ -186,7 +186,6 @@ pub enum RequestType { Move = 174, SInterCard = 175, XRevRange = 176, - SortReadOnly = 177, Copy = 178, MSetNX = 179, LPos = 180, diff --git a/python/python/glide/async_commands/cluster_commands.py b/python/python/glide/async_commands/cluster_commands.py index 8e0ee66f20..53fcf30b65 100644 --- a/python/python/glide/async_commands/cluster_commands.py +++ b/python/python/glide/async_commands/cluster_commands.py @@ -660,11 +660,11 @@ async def sort( async def sort_ro( self, - key: str, + key: TEncodable, limit: Optional[Limit] = None, order: Optional[OrderBy] = None, alpha: Optional[bool] = None, - ) -> List[str]: + ) -> List[bytes]: """ Sorts the elements in the list, set, or sorted set at `key` and returns the result. This command is routed depending on the client's `ReadFrom` strategy. @@ -674,7 +674,7 @@ async def sort_ro( See https://valkey.io/commands/sort_ro for more details. Args: - key (str): The key of the list, set, or sorted set to be sorted. + key (TEncodable): The key of the list, set, or sorted set to be sorted. limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for more information. order (Optional[OrderBy]): Specifies the order to sort the elements. Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending). @@ -682,23 +682,23 @@ async def sort_ro( Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers. Returns: - List[str]: A list of sorted elements. + List[bytes]: A list of sorted elements. Examples: >>> await client.lpush("mylist", '3', '1', '2') >>> await client.sort_ro("mylist") - ['1', '2', '3'] + [b'1', b'2', b'3'] >>> await client.sort_ro("mylist", order=OrderBy.DESC) - ['3', '2', '1'] + [b'3', b'2', b'1'] >>> await client.lpush("mylist", '2', '1', '2', '3', '3', '1') >>> await client.sort_ro("mylist", limit=Limit(2, 3)) - ['1', '2', '2'] + [b'1', b'2', b'2'] >>> await client.lpush("mylist", "a", "b", "c", "d") >>> await client.sort_ro("mylist", limit=Limit(2, 2), order=OrderBy.DESC, alpha=True) - ['b', 'a'] + [b'b', b'a'] Since: Redis version 7.0.0. """ diff --git a/python/python/glide/async_commands/standalone_commands.py b/python/python/glide/async_commands/standalone_commands.py index a24c6c2729..ff7d0eab92 100644 --- a/python/python/glide/async_commands/standalone_commands.py +++ b/python/python/glide/async_commands/standalone_commands.py @@ -488,13 +488,13 @@ async def sort( async def sort_ro( self, - key: str, - by_pattern: Optional[str] = None, + key: TEncodable, + by_pattern: Optional[TEncodable] = None, limit: Optional[Limit] = None, - get_patterns: Optional[List[str]] = None, + get_patterns: Optional[List[TEncodable]] = None, order: Optional[OrderBy] = None, alpha: Optional[bool] = None, - ) -> List[Optional[str]]: + ) -> List[Optional[bytes]]: """ Sorts the elements in the list, set, or sorted set at `key` and returns the result. The `sort_ro` command can be used to sort elements based on different criteria and apply transformations on sorted elements. @@ -502,8 +502,8 @@ async def sort_ro( See https://valkey.io/commands/sort_ro for more details. Args: - key (str): The key of the list, set, or sorted set to be sorted. - by_pattern (Optional[str]): A pattern to sort by external keys instead of by the elements stored at the key themselves. + key (TEncodable): The key of the list, set, or sorted set to be sorted. + by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key themselves. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects, `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or @@ -512,7 +512,7 @@ async def sort_ro( keys `weight_`. If not provided, elements are sorted by their value. limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for more information. - get_pattern (Optional[str]): A pattern used to retrieve external keys' values, instead of the elements at `key`. + get_pattern (Optional[TEncodable]): A pattern used to retrieve external keys' values, instead of the elements at `key`. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from `key` replaces the asterisk to create the key name. This allows the sorted elements to be transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern` @@ -527,28 +527,28 @@ async def sort_ro( Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point Returns: - List[Optional[str]]: Returns a list of sorted elements. + List[Optional[bytes]]: Returns a list of sorted elements. Examples: >>> await client.lpush("mylist", 3, 1, 2) >>> await client.sort_ro("mylist") - ['1', '2', '3'] + [b'1', b'2', b'3'] >>> await client.sort_ro("mylist", order=OrderBy.DESC) - ['3', '2', '1'] + [b'3', b'2', b'1'] >>> await client.lpush("mylist2", 2, 1, 2, 3, 3, 1) >>> await client.sort_ro("mylist2", limit=Limit(2, 3)) - ['2', '2', '3'] + [b'2', b'2', b'3'] >>> await client.hset("user:1", "name", "Alice", "age", 30) >>> await client.hset("user:2", "name", "Bob", "age", 25) >>> await client.lpush("user_ids", 2, 1) >>> await client.sort_ro("user_ids", by_pattern="user:*->age", get_patterns=["user:*->name"]) - ['Bob', 'Alice'] + [b'Bob', b'Alice'] Since: Redis version 7.0.0. """ args = _build_sort_args(key, by_pattern, limit, get_patterns, order, alpha) result = await self._execute_command(RequestType.SortReadOnly, args) - return cast(List[Optional[str]], result) + return cast(List[Optional[bytes]], result) async def sort_store( self, diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 5dc86aff9c..34dec7e833 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -4649,10 +4649,10 @@ def sort( def sort_ro( self: TTransaction, - key: str, - by_pattern: Optional[str] = None, + key: TEncodable, + by_pattern: Optional[TEncodable] = None, limit: Optional[Limit] = None, - get_patterns: Optional[List[str]] = None, + get_patterns: Optional[List[TEncodable]] = None, order: Optional[OrderBy] = None, alpha: Optional[bool] = None, ) -> TTransaction: @@ -4663,8 +4663,8 @@ def sort_ro( See https://valkey.io/commands/sort_ro for more details. Args: - key (str): The key of the list, set, or sorted set to be sorted. - by_pattern (Optional[str]): A pattern to sort by external keys instead of by the elements stored at the key themselves. + key (TEncodable): The key of the list, set, or sorted set to be sorted. + by_pattern (Optional[TEncodable]): A pattern to sort by external keys instead of by the elements stored at the key themselves. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from the key replaces the asterisk to create the key name. For example, if `key` contains IDs of objects, `by_pattern` can be used to sort these IDs based on an attribute of the objects, like their weights or @@ -4673,7 +4673,7 @@ def sort_ro( keys `weight_`. If not provided, elements are sorted by their value. limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for more information. - get_pattern (Optional[str]): A pattern used to retrieve external keys' values, instead of the elements at `key`. + get_pattern (Optional[TEncodable]): A pattern used to retrieve external keys' values, instead of the elements at `key`. The pattern should contain an asterisk (*) as a placeholder for the element values, where the value from `key` replaces the asterisk to create the key name. This allows the sorted elements to be transformed based on the related keys values. For example, if `key` contains IDs of users, `get_pattern` @@ -4688,7 +4688,7 @@ def sort_ro( Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers. Command response: - List[Optional[str]]: Returns a list of sorted elements. + List[Optional[bytes]]: Returns a list of sorted elements. Since: Redis version 7.0.0. """ @@ -4837,7 +4837,7 @@ def sort( def sort_ro( self: TTransaction, - key: str, + key: TEncodable, limit: Optional[Limit] = None, order: Optional[OrderBy] = None, alpha: Optional[bool] = None, @@ -4848,7 +4848,7 @@ def sort_ro( See https://valkey.io/commands/sort_ro for more details. Args: - key (str): The key of the list, set, or sorted set to be sorted. + key (TEncodable): The key of the list, set, or sorted set to be sorted. limit (Optional[Limit]): Limiting the range of the query by setting offset and result count. See `Limit` class for more information. order (Optional[OrderBy]): Specifies the order to sort the elements. Can be `OrderBy.ASC` (ascending) or `OrderBy.DESC` (descending). @@ -4856,7 +4856,7 @@ def sort_ro( Use this when the list, set, or sorted set contains string values that cannot be converted into double precision floating point numbers. Command response: - List[str]: A list of sorted elements. + List[bytes]: A list of sorted elements. Since: Redis version 7.0.0. """ diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 6103f73189..356b631f6f 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -4739,7 +4739,7 @@ async def test_sort_and_sort_store_with_get_or_by_args( order=OrderBy.ASC, alpha=True, ) - assert result_ro == ["Alice", "Bob"] + assert result_ro == [b"Alice", b"Bob"] # Test sort_store with all arguments sort_store_result = await redis_client.sort_store( @@ -4772,7 +4772,7 @@ async def test_sort_and_sort_store_with_get_or_by_args( get_patterns=["user:*->name"], alpha=True, ) - assert result_ro == ["Dave", "Bob", "Alice", "Charlie", "Eve"] + assert result_ro == [b"Dave", b"Bob", b"Alice", b"Charlie", b"Eve"] # Test sort with `by` argument with missing keys to sort by assert await redis_client.lpush("user_ids", ["a"]) == 6 @@ -4793,7 +4793,7 @@ async def test_sort_and_sort_store_with_get_or_by_args( get_patterns=["user:*->name"], alpha=True, ) - assert result_ro == [None, "Dave", "Bob", "Alice", "Charlie", "Eve"] + assert result_ro == [None, b"Dave", b"Bob", b"Alice", b"Charlie", b"Eve"] # Test sort with `by` argument with missing keys to sort by result = await redis_client.sort( @@ -4813,7 +4813,7 @@ async def test_sort_and_sort_store_with_get_or_by_args( get_patterns=["user:*->age"], alpha=True, ) - assert result_ro == [None, "30", "25", "35", "20", "40"] + assert result_ro == [None, b"30", b"25", b"35", b"20", b"40"] # Test Limit with count 0 result = await redis_client.sort( @@ -4868,7 +4868,7 @@ async def test_sort_and_sort_store_without_get_or_by_args( if not skip_sort_ro_test: result_ro = await redis_client.sort_ro(key) - assert result_ro == ["1", "2", "3", "4", "5"] + assert result_ro == [b"1", b"2", b"3", b"4", b"5"] # limit argument result = await redis_client.sort(key, limit=Limit(1, 3)) @@ -4876,7 +4876,7 @@ async def test_sort_and_sort_store_without_get_or_by_args( if not skip_sort_ro_test: result_ro = await redis_client.sort_ro(key, limit=Limit(1, 3)) - assert result_ro == ["2", "3", "4"] + assert result_ro == [b"2", b"3", b"4"] # order argument result = await redis_client.sort(key, order=OrderBy.DESC) @@ -4884,7 +4884,7 @@ async def test_sort_and_sort_store_without_get_or_by_args( if not skip_sort_ro_test: result_ro = await redis_client.sort_ro(key, order=OrderBy.DESC) - assert result_ro == ["5", "4", "3", "2", "1"] + assert result_ro == [b"5", b"4", b"3", b"2", b"1"] assert await redis_client.lpush(key, ["a"]) == 6 @@ -4903,7 +4903,7 @@ async def test_sort_and_sort_store_without_get_or_by_args( if not skip_sort_ro_test: result_ro = await redis_client.sort_ro(key, alpha=True) - assert result_ro == ["1", "2", "3", "4", "5", "a"] + assert result_ro == [b"1", b"2", b"3", b"4", b"5", b"a"] # Combining multiple arguments result = await redis_client.sort( @@ -4915,7 +4915,7 @@ async def test_sort_and_sort_store_without_get_or_by_args( result_ro = await redis_client.sort_ro( key, limit=Limit(1, 3), order=OrderBy.DESC, alpha=True ) - assert result_ro == ["5", "4", "3"] + assert result_ro == [b"5", b"4", b"3"] # Test sort_store with combined arguments sort_store_result = await redis_client.sort_store( diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 4c5c977710..2ceebf58c4 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -918,8 +918,8 @@ async def test_standalone_transaction(self, redis_client: GlideClient): assert isinstance(result[0], str) assert "# Memory" in result[0] assert result[1:5] == [OK, False, OK, value.encode()] - assert result[5:14] == [2, 2, 2, [b"Bob", b"Alice"], [b"Bob", b"Alice"], 2, OK, None, 0] - assert result[14:] == expected + assert result[5:13] == [2, 2, 2, [b"Bob", b"Alice"], 2, OK, None, 0] + assert result[13:] == expected def test_transaction_clear(self): transaction = Transaction()