Skip to content

Commit

Permalink
Add AsyncFunctionCommands (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Chen-Wang authored Feb 24, 2022
1 parent 1256fdd commit afc83e1
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5485,6 +5485,9 @@ def readonly(self, **kwargs) -> ResponseT:
return self.execute_command("READONLY", **kwargs)


AsyncClusterCommands = ClusterCommands


class FunctionCommands:
"""
Redis Function commands
Expand All @@ -5497,7 +5500,7 @@ def function_load(
code: str,
replace: Optional[bool] = False,
description: Optional[str] = None,
) -> str:
) -> Union[Awaitable[str], str]:
"""
Load a library to Redis.
:param engine: the name of the execution engine for the library
Expand All @@ -5517,15 +5520,15 @@ def function_load(
pieces.append(code)
return self.execute_command("FUNCTION LOAD", *pieces)

def function_delete(self, library: str) -> str:
def function_delete(self, library: str) -> Union[Awaitable[str], str]:
"""
Delete the library called ``library`` and all its functions.
For more information check https://redis.io/commands/function-delete
"""
return self.execute_command("FUNCTION DELETE", library)

def function_flush(self, mode: str = "SYNC") -> str:
def function_flush(self, mode: str = "SYNC") -> Union[Awaitable[str], str]:
"""
Deletes all the libraries.
Expand All @@ -5535,7 +5538,7 @@ def function_flush(self, mode: str = "SYNC") -> str:

def function_list(
self, library: Optional[str] = "*", withcode: Optional[bool] = False
) -> List:
) -> Union[Awaitable[list], list]:
"""
Return information about the functions and libraries.
:param library: pecify a pattern for matching library names
Expand All @@ -5549,18 +5552,22 @@ def function_list(

def _fcall(
self, command: str, function, numkeys: int, *keys_and_args: Optional[List]
) -> str:
) -> Union[Awaitable[str], str]:
return self.execute_command(command, function, numkeys, *keys_and_args)

def fcall(self, function, numkeys: int, *keys_and_args: Optional[List]) -> str:
def fcall(
self, function, numkeys: int, *keys_and_args: Optional[List]
) -> Union[Awaitable[str], str]:
"""
Invoke a function.
For more information check https://redis.io/commands/fcall
"""
return self._fcall("FCALL", function, numkeys, *keys_and_args)

def fcall_ro(self, function, numkeys: int, *keys_and_args: Optional[List]) -> str:
def fcall_ro(
self, function, numkeys: int, *keys_and_args: Optional[List]
) -> Union[Awaitable[str], str]:
"""
This is a read-only variant of the FCALL command that cannot
execute commands that modify data.
Expand All @@ -5569,7 +5576,7 @@ def fcall_ro(self, function, numkeys: int, *keys_and_args: Optional[List]) -> st
"""
return self._fcall("FCALL_RO", function, numkeys, *keys_and_args)

def function_dump(self) -> str:
def function_dump(self) -> Union[Awaitable[str], str]:
"""
Return the serialized payload of loaded libraries.
Expand All @@ -5582,7 +5589,9 @@ def function_dump(self) -> str:

return self.execute_command("FUNCTION DUMP", **options)

def function_restore(self, payload: str, policy: Optional[str] = "APPEND") -> str:
def function_restore(
self, payload: str, policy: Optional[str] = "APPEND"
) -> Union[Awaitable[str], str]:
"""
Restore libraries from the serialized ``payload``.
You can use the optional policy argument to provide a policy
Expand All @@ -5592,15 +5601,15 @@ def function_restore(self, payload: str, policy: Optional[str] = "APPEND") -> st
"""
return self.execute_command("FUNCTION RESTORE", payload, policy)

def function_kill(self) -> str:
def function_kill(self) -> Union[Awaitable[str], str]:
"""
Kill a function that is currently executing.
For more information check https://redis.io/commands/function-kill
"""
return self.execute_command("FUNCTION KILL")

def function_stats(self) -> list:
def function_stats(self) -> Union[Awaitable[list], list]:
"""
Return information about the function that's currently running
and information about the available execution engines.
Expand All @@ -5610,7 +5619,7 @@ def function_stats(self) -> list:
return self.execute_command("FUNCTION STATS")


AsyncClusterCommands = ClusterCommands
AsyncFunctionCommands = FunctionCommands


class DataAccessCommands(
Expand Down Expand Up @@ -5671,6 +5680,7 @@ class AsyncCoreCommands(
AsyncModuleCommands,
AsyncPubSubCommands,
AsyncScriptCommands,
AsyncFunctionCommands,
):
"""
A class containing all of the implemented redis commands. This class is
Expand Down

0 comments on commit afc83e1

Please sign in to comment.