@@ -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 ]
0 commit comments