Execute Redis command with error handling and reconnection logic
(self, command_func, *args, **kwargs)
| 120 | logger.error(f"Failed to connect to Redis after {self.redis_max_retries} attempts") |
| 121 | |
| 122 | def _execute_redis_command(self, command_func, *args, **kwargs): |
| 123 | """Execute Redis command with error handling and reconnection logic""" |
| 124 | if not self.redis_client: |
| 125 | return None |
| 126 | |
| 127 | try: |
| 128 | return command_func(*args, **kwargs) |
| 129 | except (ConnectionError, TimeoutError) as e: |
| 130 | logger.warning(f"Redis connection lost: {e}. Attempting to reconnect...") |
| 131 | try: |
| 132 | # Try to reconnect |
| 133 | self.redis_connection_attempts = 0 |
| 134 | self._setup_redis_connection() |
| 135 | if self.redis_client: |
| 136 | # Retry the command once |
| 137 | return command_func(*args, **kwargs) |
| 138 | except Exception as reconnect_error: |
| 139 | logger.error(f"Failed to reconnect to Redis: {reconnect_error}") |
| 140 | return None |
| 141 | except Exception as e: |
| 142 | logger.error(f"Redis command error: {e}") |
| 143 | return None |
| 144 | |
| 145 | def _spawn_on_hub(self, fn, *args, **kwargs): |
| 146 | """Schedule fn on the gevent hub from any thread without blocking the caller.""" |
no test coverage detected