def __getstate__(self):
        """Get the state for redis serialization.

        This method is called by pickle to serialize the object.

        It explicitly removes parent_state and substates because those are serialized separately
        by the StateManagerRedis to allow for better horizontal scaling as state size increases.

        Returns:
            The state dict for serialization.
        """
        state = self.__dict__
        state = state.copy()
        if state.get("parent_state") is not None:
            # Do not serialize router data in substates (only the root state).
            state.pop("router", None)
            state.pop("router_data", None)
        # Never serialize parent_state or substates.
        state.pop("parent_state", None)
        state.pop("substates", None)
        state.pop("_was_touched", None)
        # Remove all inherited vars.
        for inherited_var_name in self.inherited_vars:
            state.pop(inherited_var_name, None)
        return state
Get the state for redis serialization.

        This method is called by pickle to serialize the object.

        It explicitly removes parent_state and substates because those are serialized separately
        by the StateManagerRedis to allow for better horizontal scaling as state size increases.

        Returns:
            The state dict for serialization.
        
reflex/state.py