Handle a stash operation directly in the arbiter. All stash tables are stored in arbiter memory for simplicity and fast access. Args: message: Stash operation message client_writer: StreamWriter to send response to client
(self, message, client_writer)
| 789 | await DirtyProtocol.write_message_async(client_writer, response) |
| 790 | |
| 791 | async def handle_stash_request(self, message, client_writer): |
| 792 | """ |
| 793 | Handle a stash operation directly in the arbiter. |
| 794 | |
| 795 | All stash tables are stored in arbiter memory for simplicity |
| 796 | and fast access. |
| 797 | |
| 798 | Args: |
| 799 | message: Stash operation message |
| 800 | client_writer: StreamWriter to send response to client |
| 801 | """ |
| 802 | request_id = message.get("id", "unknown") |
| 803 | op = message.get("op") |
| 804 | table = message.get("table", "") |
| 805 | key = message.get("key") |
| 806 | value = message.get("value") |
| 807 | pattern = message.get("pattern") |
| 808 | |
| 809 | try: |
| 810 | result = None |
| 811 | |
| 812 | if op == STASH_OP_PUT: |
| 813 | # Auto-create table if needed |
| 814 | if table not in self.stash_tables: |
| 815 | self.stash_tables[table] = {} |
| 816 | self.stash_tables[table][key] = value |
| 817 | result = True |
| 818 | |
| 819 | elif op == STASH_OP_GET: |
| 820 | if table not in self.stash_tables: |
| 821 | result = {"error": "key_not_found"} |
| 822 | elif key not in self.stash_tables[table]: |
| 823 | result = {"error": "key_not_found"} |
| 824 | else: |
| 825 | result = self.stash_tables[table][key] |
| 826 | |
| 827 | elif op == STASH_OP_DELETE: |
| 828 | if table in self.stash_tables and key in self.stash_tables[table]: |
| 829 | del self.stash_tables[table][key] |
| 830 | result = True |
| 831 | else: |
| 832 | result = False |
| 833 | |
| 834 | elif op == STASH_OP_KEYS: |
| 835 | if table not in self.stash_tables: |
| 836 | result = [] |
| 837 | else: |
| 838 | all_keys = list(self.stash_tables[table].keys()) |
| 839 | if pattern: |
| 840 | all_keys = [k for k in all_keys |
| 841 | if fnmatch.fnmatch(str(k), pattern)] |
| 842 | result = all_keys |
| 843 | |
| 844 | elif op == STASH_OP_CLEAR: |
| 845 | if table in self.stash_tables: |
| 846 | self.stash_tables[table].clear() |
| 847 | result = True |
| 848 |
no test coverage detected