Skip to content

Commit

Permalink
addressed Run isort . --profile black --check --diff
Browse files Browse the repository at this point in the history
  • Loading branch information
GilboaAWS committed May 26, 2024
1 parent 265e513 commit 75660c2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
4 changes: 2 additions & 2 deletions python/python/glide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
GeoUnit,
InfoSection,
InsertPosition,
SortOrder,
StreamAddOptions,
StreamTrimOptions,
TrimByMaxLen,
TrimByMinId,
UpdateOptions,
SortOrder,
)
from glide.async_commands.redis_modules import json
from glide.async_commands.sorted_set import (
Expand Down Expand Up @@ -103,12 +103,12 @@
"RangeByLex",
"RangeByScore",
"ScoreFilter",
"SortOrder",
"StreamAddOptions",
"StreamTrimOptions",
"TrimByMaxLen",
"TrimByMinId",
"UpdateOptions",
"SortOrder",
# Logger
"Logger",
"LogLevel",
Expand Down
2 changes: 1 addition & 1 deletion python/python/glide/async_commands/cluster_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Dict, List, Mapping, Optional, cast, Tuple
from typing import Dict, List, Mapping, Optional, Tuple, cast

from glide.async_commands.core import (
CoreCommands,
Expand Down
10 changes: 7 additions & 3 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ class UpdateOptions(Enum):
class SortOrder(Enum):
"""
SORT order options: options for sorting elements.
- ASC: Sort in ascending order.
- DESC: Sort in descending order.
"""

ASC = "ASC"
"""
ASC: Sort in ascending order.
"""

DESC = "DESC"
"""
DESC: Sort in descending order.
"""


class GeospatialData:
Expand Down
2 changes: 1 addition & 1 deletion python/python/glide/async_commands/standalone_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Dict, List, Mapping, Optional, cast, Tuple
from typing import Dict, List, Mapping, Optional, Tuple, cast

from glide.async_commands.core import (
CoreCommands,
Expand Down
10 changes: 5 additions & 5 deletions python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
GeoUnit,
InfoSection,
InsertPosition,
SortOrder,
StreamAddOptions,
StreamTrimOptions,
UpdateOptions,
SortOrder,
_build_sort_args,
)
from glide.async_commands.sorted_set import (
Expand Down Expand Up @@ -2543,12 +2543,12 @@ class ClusterTransaction(BaseTransaction):
"""

def sort(
self,
self: TTransaction,
key: str,
limit: Optional[Tuple[int, int]] = None,
order: Optional[SortOrder] = None,
alpha: Optional[bool] = None,
) -> List[Optional[str]]:
) -> TTransaction:
"""
Sorts the elements in the list, set, or sorted set at `key` and returns the result.
To store the result into a new key, see `sort_store`.
Expand All @@ -2568,13 +2568,13 @@ def sort(
return self.append_command(RequestType.Sort, args)

def sort_store(
self,
self: TTransaction,
key: str,
store: str,
limit: Optional[Tuple[int, int]] = None,
order: Optional[SortOrder] = None,
alpha: Optional[bool] = None,
) -> int:
) -> TTransaction:
"""
Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`.
When in cluster mode, `key` and `store` must map to the same hash slot.
Expand Down
73 changes: 38 additions & 35 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
InfBound,
InfoSection,
InsertPosition,
SortOrder,
StreamAddOptions,
TrimByMaxLen,
TrimByMinId,
UpdateOptions,
SortOrder,
)
from glide.async_commands.sorted_set import (
AggregationType,
Expand Down Expand Up @@ -3198,38 +3198,39 @@ async def test_sort_and_sort_store_with_get_or_by_args(
assert await redis_client.hset(user_key5, {"name": "Eve", "age": "40"}) == 2
assert await redis_client.lpush("user_ids", ["5", "4", "3", "2", "1"]) == 5

# Test sort with all arguments
assert await redis_client.lpush(key, ["3", "1", "2"]) == 3
result = await redis_client.sort(
key,
limit=(0, 2),
get_patterns=["user:*->name"],
order=SortOrder.ASC,
alpha=True,
)
assert result == ["Alice", "Bob"]
if isinstance(redis_client, RedisClient):
# Test sort with all arguments
assert await redis_client.lpush(key, ["3", "1", "2"]) == 3
result = await redis_client.sort(
key,
limit=(0, 2),
get_patterns=["user:*->name"],
order=SortOrder.ASC,
alpha=True,
)
assert result == ["Alice", "Bob"]

# Test sort_store with all arguments
result = await redis_client.sort_store(
key,
store,
limit=(0, 2),
get_patterns=["user:*->name"],
order=SortOrder.ASC,
alpha=True,
)
assert result == 2
sorted_list = await redis_client.lrange(store, 0, -1)
assert sorted_list == ["Alice", "Bob"]
# Test sort_store with all arguments
sort_store_result = await redis_client.sort_store(
key,
store,
limit=(0, 2),
get_patterns=["user:*->name"],
order=SortOrder.ASC,
alpha=True,
)
assert sort_store_result == 2
sorted_list = await redis_client.lrange(store, 0, -1)
assert sorted_list == ["Alice", "Bob"]

# Test sort with `by` argument
result = await redis_client.sort(
"user_ids",
by_pattern="user:*->age",
get_patterns=["user:*->name"],
alpha=True,
)
assert result == ["Dave", "Bob", "Alice", "Charlie", "Eve"]
# Test sort with `by` argument
result = await redis_client.sort(
"user_ids",
by_pattern="user:*->age",
get_patterns=["user:*->name"],
alpha=True,
)
assert result == ["Dave", "Bob", "Alice", "Charlie", "Eve"]

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
Expand All @@ -3244,8 +3245,10 @@ async def test_sort_and_sort_store_without_get_or_by_args(
assert result == []

# Test sort_store with non-existing key
result = await redis_client.sort_store("{SameSlotKey}:non_existing_key", store)
assert result == 0
sort_store_result = await redis_client.sort_store(
"{SameSlotKey}:non_existing_key", store
)
assert sort_store_result == 0

# Test each argument separately
assert await redis_client.lpush(key, ["5", "2", "4", "1", "3"]) == 5
Expand Down Expand Up @@ -3279,10 +3282,10 @@ async def test_sort_and_sort_store_without_get_or_by_args(
assert result == ["5", "4", "3"]

# Test sort_store with combined arguments
result = await redis_client.sort_store(
sort_store_result = await redis_client.sort_store(
key, store, limit=(1, 3), order=SortOrder.DESC, alpha=True
)
assert result == 3
assert sort_store_result == 3
sorted_list = await redis_client.lrange(store, 0, -1)
assert sorted_list == ["5", "4", "3"]

Expand Down

0 comments on commit 75660c2

Please sign in to comment.