diff options
Diffstat (limited to 'redis/commands/parser.py')
-rw-r--r-- | redis/commands/parser.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/redis/commands/parser.py b/redis/commands/parser.py index 936f2ec..7560603 100644 --- a/redis/commands/parser.py +++ b/redis/commands/parser.py @@ -25,6 +25,21 @@ class CommandsParser: commands[cmd.lower()] = commands.pop(cmd) self.commands = commands + def parse_subcommand(self, command, **options): + cmd_dict = {} + cmd_name = str_if_bytes(command[0]) + cmd_dict["name"] = cmd_name + cmd_dict["arity"] = int(command[1]) + cmd_dict["flags"] = [str_if_bytes(flag) for flag in command[2]] + cmd_dict["first_key_pos"] = command[3] + cmd_dict["last_key_pos"] = command[4] + cmd_dict["step_count"] = command[5] + if len(command) > 7: + cmd_dict["tips"] = command[7] + cmd_dict["key_specifications"] = command[8] + cmd_dict["subcommands"] = command[9] + return cmd_dict + # As soon as this PR is merged into Redis, we should reimplement # our logic to use COMMAND INFO changes to determine the key positions # https://github.com/redis/redis/pull/8324 @@ -72,8 +87,17 @@ class CommandsParser: and command["first_key_pos"] == 0 and command["last_key_pos"] == 0 ): + is_subcmd = False + if "subcommands" in command: + subcmd_name = f"{cmd_name}|{args[1].lower()}" + for subcmd in command["subcommands"]: + if str_if_bytes(subcmd[0]) == subcmd_name: + command = self.parse_subcommand(subcmd) + is_subcmd = True + # The command doesn't have keys in it - return None + if not is_subcmd: + return None last_key_pos = command["last_key_pos"] if last_key_pos < 0: last_key_pos = len(args) - abs(last_key_pos) |