Skip to content

Commit 8843b6f

Browse files
authored
PYTHON: Fix documentation for copy command (#4859)
fix documentation for copy command Signed-off-by: affonsov <[email protected]>
1 parent b48abac commit 8843b6f

File tree

2 files changed

+32
-69
lines changed

2 files changed

+32
-69
lines changed

python/glide-async/python/glide/async_commands/cluster_commands.py

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,16 @@ async def flushdb(
10621062
await self._execute_command(RequestType.FlushDB, args, route),
10631063
)
10641064

1065+
async def copy(
1066+
self,
1067+
source: TEncodable,
1068+
destination: TEncodable,
1069+
# TODO next major release the arguments replace and destinationDB must have their order
1070+
# swapped to align with the standalone order.
1071+
# At the moment of the patch release 2.1.1. we can't have a breaking change
1072+
replace: Optional[bool] = None,
1073+
destinationDB: Optional[int] = None,
1074+
) -> bool:
10651075
"""
10661076
Copies the value stored at the `source` to the `destination` key. If `destinationDB`
10671077
is specified, the value will be copied to the database specified by `destinationDB`,
@@ -1070,57 +1080,31 @@ async def flushdb(
10701080
10711081
See [valkey.io](https://valkey.io/commands/copy) for more details.
10721082
1083+
Note:
1084+
Both `source` and `destination` must map to the same hash slot.
1085+
10731086
Args:
10741087
source (TEncodable): The key to the source value.
10751088
destination (TEncodable): The key where the value should be copied to.
1076-
destinationDB (Optional[Union[int, str]]): The alternative logical database index for the destination key.
10771089
replace (Optional[bool]): If the destination key should be removed before copying the value to it.
1090+
destinationDB (Optional[int]): The alternative logical database index for the destination key.
10781091
10791092
Returns:
1080-
bool: True if the source was copied. Otherwise, return False.
1093+
bool: True if the source was copied. Otherwise, returns False.
10811094
10821095
Examples:
10831096
>>> await client.set("source", "sheep")
1097+
>>> await client.copy(b"source", b"destination")
1098+
True # Source was copied
10841099
>>> await client.copy(b"source", b"destination", destinationDB=1)
10851100
True # Source was copied to DB 1
10861101
>>> await client.select(1)
10871102
>>> await client.get("destination")
10881103
b"sheep"
10891104
1090-
Since: Valkey version 9.0.0.
1091-
"""
1092-
...
1093-
1094-
async def copy(
1095-
self,
1096-
source: TEncodable,
1097-
destination: TEncodable,
1098-
# TODO next major release the arguments replace and destinationDB must have their order
1099-
# swapped to align with the standalone order.
1100-
# At the moment of the patch release 2.1.1. we can't have a breaking change
1101-
replace: Optional[bool] = None,
1102-
destinationDB: Optional[int] = None,
1103-
) -> bool:
1104-
"""
1105-
Copies the value stored at the `source` to the `destination` key.
1106-
1107-
This method supports two signatures:
1108-
1. copy(source, destination, replace=None) - original API
1109-
2. copy(source, destination, replace=None, destinationDB=None) - new API with DB support
1110-
1111-
When `replace` is True, removes the `destination` key first if it already exists,
1112-
otherwise performs no action.
1113-
1114-
See [valkey.io](https://valkey.io/commands/copy) for more details.
1115-
1116-
Note:
1117-
When `destinationDB` is not provided, both `source` and `destination` must map to the same hash slot.
1105+
Since: Valkey version 6.2.0.
1106+
The destinationDB argument is available since Valkey 9.0.0
11181107
"""
1119-
# Handle backward compatibility for positional arguments
1120-
# If destinationDB is a boolean, it's likely the old API: copy(source, destination, replace)
1121-
if isinstance(destinationDB, bool):
1122-
replace = destinationDB
1123-
destinationDB = None
11241108

11251109
# Build command arguments
11261110
args: List[TEncodable] = [source, destination]

python/glide-sync/glide_sync/sync_commands/cluster_commands.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,16 @@ def flushdb(
952952
self._execute_command(RequestType.FlushDB, args, route),
953953
)
954954

955+
def copy(
956+
self,
957+
source: TEncodable,
958+
destination: TEncodable,
959+
# TODO next major release the arguments replace and destinationDB must have their order
960+
# swapped to align with the standalone order.
961+
# At the moment of the patch release 2.1.1. we can't have a breaking change
962+
replace: Optional[bool] = None,
963+
destinationDB: Optional[int] = None,
964+
) -> bool:
955965
"""
956966
Copies the value stored at the `source` to the `destination` key. If `destinationDB`
957967
is specified, the value will be copied to the database specified by `destinationDB`,
@@ -963,8 +973,8 @@ def flushdb(
963973
Args:
964974
source (TEncodable): The key to the source value.
965975
destination (TEncodable): The key where the value should be copied to.
966-
destinationDB (Optional[Union[int, str]]): The alternative logical database index for the destination key.
967976
replace (Optional[bool]): If the destination key should be removed before copying the value to it.
977+
destinationDB (Optional[int]): The alternative logical database index for the destination key.
968978
969979
Returns:
970980
bool: True if the source was copied. Otherwise, return False.
@@ -977,40 +987,9 @@ def flushdb(
977987
>>> client.get("destination")
978988
b"sheep"
979989
980-
Since: Valkey version 9.0.0.
981-
"""
982-
...
983-
984-
def copy(
985-
self,
986-
source: TEncodable,
987-
destination: TEncodable,
988-
# TODO next major release the arguments replace and destinationDB must have their order
989-
# swapped to align with the standalone order.
990-
# At the moment of the patch release 2.1.1. we can't have a breaking change
991-
replace: Optional[bool] = None,
992-
destinationDB: Optional[int] = None,
993-
) -> bool:
994-
"""
995-
Copies the value stored at the `source` to the `destination` key.
996-
997-
This method supports two signatures:
998-
1. copy(source, destination, replace=None) - original API
999-
2. copy(source, destination, replace=None, destinationDB=None) - new API with DB support
1000-
1001-
When `replace` is True, removes the `destination` key first if it already exists,
1002-
otherwise performs no action.
1003-
1004-
See [valkey.io](https://valkey.io/commands/copy) for more details.
1005-
1006-
Note:
1007-
When `destinationDB` is not provided, both `source` and `destination` must map to the same hash slot.
990+
Since: Valkey version 6.2.0.
991+
The destinationDB argument is available since Valkey 9.0.0
1008992
"""
1009-
# Handle backward compatibility for positional arguments
1010-
# If destinationDB is a boolean, it's likely the old API: copy(source, destination, replace)
1011-
if isinstance(destinationDB, bool):
1012-
replace = destinationDB
1013-
destinationDB = None
1014993

1015994
# Build command arguments
1016995
args: List[TEncodable] = [source, destination]

0 commit comments

Comments
 (0)