Skip to content

Commit

Permalink
chnage json.type type
Browse files Browse the repository at this point in the history
Signed-off-by: Shoham Elias <shohame@amazon.com>
  • Loading branch information
shohamazon committed Oct 14, 2024
1 parent d129ce6 commit c1f20d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions python/python/glide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
TFunctionListResponse,
TFunctionStatsFullResponse,
TFunctionStatsSingleNodeResponse,
TJsonResponse,
TJsonUniversalResponse,
TResult,
TSingleNodeRoute,
TXInfoStreamFullResponse,
Expand Down Expand Up @@ -161,6 +163,8 @@
"TFunctionListResponse",
"TFunctionStatsFullResponse",
"TFunctionStatsSingleNodeResponse",
"TJsonResponse",
"TJsonUniversalResponse",
"TOK",
"TResult",
"TXInfoStreamFullResponse",
Expand Down
8 changes: 5 additions & 3 deletions python/python/glide/async_commands/server_modules/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async def type(
client: TGlideClient,
key: TEncodable,
path: Optional[TEncodable] = None,
) -> Optional[Union[bytes, List[bytes]]]:
) -> Optional[TJsonUniversalResponse[bytes]]:
"""
Retrieves the type of the JSON value at the specified `path` within the JSON document stored at `key`.
Expand All @@ -431,7 +431,7 @@ async def type(
Defaults to None.
Returns:
Optional[Union[bytes, List[bytes]]]:
Optional[TJsonUniversalResponse[bytes]]:
For JSONPath ('path' starts with '$'):
Returns a list of byte string replies for every possible path, indicating the type of the JSON value.
If `path` doesn't exist, an empty array will be returned.
Expand All @@ -455,4 +455,6 @@ async def type(
if path:
args.append(path)

return cast(Optional[Union[bytes, List[bytes]]], await client.custom_command(args))
return cast(
Optional[TJsonUniversalResponse[bytes]], await client.custom_command(args)
)
16 changes: 15 additions & 1 deletion python/python/glide/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@
TSingleNodeRoute = Union[RandomNode, SlotKeyRoute, SlotIdRoute, ByAddressRoute]
# When specifying legacy path (path doesn't start with `$`), response will be T
# Otherwise, (when specifying JSONPath), response will be List[Optional[T]].
#
# Explanation:
# TJsonResponse is designed to handle scenarios where some paths may not contain valid values, especially with JSONPath targeting multiple paths.
# In such cases, the response may include None values, represented as `Optional[T]` in the list.
# This type provides flexibility for commands where a subset of the paths may return None.
#
# For more information, see: https://redis.io/docs/data-types/json/path/ .
TJsonResponse = Union[T, List[Optional[T]]]

# When specifying legacy path (path doesn't start with `$`), response will be T
# Otherwise, (when specifying JSONPath), response will be List[T].
# This type represents the response format for commands that apply to every path and every type in a JSON document.
# It covers both singular and multiple paths, ensuring that the command returns valid results for each matched path without `null` values.
# It covers both singular and multiple paths, ensuring that the command returns valid results for each matched path without None values.
#
# Explanation:
# TJsonUniversalResponse is considered "universal" because it applies to every matched path and
# guarantees valid, non-null results across all paths, covering both singular and multiple paths.
# This type is used for commands that return results from all matched paths, ensuring that each
# path contains meaningful values without None entries (unless it's part of the commands response).
# It is typically used in scenarios where each target is expected to yield a valid response. For commands that are valid for all target types.
#
# For more information, see: https://redis.io/docs/data-types/json/path/ .
TJsonUniversalResponse = Union[T, List[T]]
TEncodable = Union[str, bytes]
Expand Down

0 comments on commit c1f20d1

Please sign in to comment.