diff options
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 9de90fb..9653f7d 100755 --- a/redis/client.py +++ b/redis/client.py @@ -22,6 +22,7 @@ from redis.exceptions import ( ResponseError, TimeoutError, WatchError, + ModuleError, ) SYM_EMPTY = b'' @@ -516,6 +517,12 @@ def parse_acl_getuser(response, **options): return data +def parse_module_result(response): + if isinstance(response, ModuleError): + raise response + return True + + class Redis(object): """ Implementation of the Redis protocol. @@ -656,6 +663,10 @@ class Redis(object): 'XPENDING': parse_xpending, 'ZADD': parse_zadd, 'ZSCAN': parse_zscan, + 'MODULE LOAD': parse_module_result, + 'MODULE UNLOAD': parse_module_result, + 'MODULE LIST': lambda response: [pairs_to_dict(module) + for module in response], } ) @@ -3306,6 +3317,28 @@ class Redis(object): return self.execute_command(command, *pieces, **kwargs) + # MODULE COMMANDS + def module_load(self, path): + """ + Loads the module from ``path``. + Raises ``ModuleError`` if a module is not found at ``path``. + """ + return self.execute_command('MODULE LOAD', path) + + def module_unload(self, name): + """ + Unloads the module ``name``. + Raises ``ModuleError`` if ``name`` is not in loaded modules. + """ + return self.execute_command('MODULE UNLOAD', name) + + def module_list(self): + """ + Returns a list of dictionaries containing the name and version of + all loaded modules. + """ + return self.execute_command('MODULE LIST') + StrictRedis = Redis |