{"id":"735d2f83d085e725","repo":"redis/redis-py","slug":"shutdown-save-and-nosave-cannot-both-be-set","errorCode":null,"errorMessage":"SHUTDOWN save and nosave cannot both be set","messagePattern":"SHUTDOWN save and nosave cannot both be set","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":2112,"sourceCode":"        force: bool = False,\n        abort: bool = False,\n        **kwargs,\n    ) -> None:\n        \"\"\"Shutdown the Redis server.  If Redis has persistence configured,\n        data will be flushed before shutdown.\n        It is possible to specify modifiers to alter the behavior of the command:\n        ``save`` will force a DB saving operation even if no save points are configured.\n        ``nosave`` will prevent a DB saving operation even if one or more save points\n        are configured.\n        ``now`` skips waiting for lagging replicas, i.e. it bypasses the first step in\n        the shutdown sequence.\n        ``force`` ignores any errors that would normally prevent the server from exiting\n        ``abort`` cancels an ongoing shutdown and cannot be combined with other flags.\n\n        For more information, see https://redis.io/commands/shutdown\n        \"\"\"\n        if save and nosave:\n            raise DataError(\"SHUTDOWN save and nosave cannot both be set\")\n        args = [\"SHUTDOWN\"]\n        if save:\n            args.append(\"SAVE\")\n        if nosave:\n            args.append(\"NOSAVE\")\n        if now:\n            args.append(\"NOW\")\n        if force:\n            args.append(\"FORCE\")\n        if abort:\n            args.append(\"ABORT\")\n        try:\n            self.execute_command(*args, **kwargs)\n        except ConnectionError:\n            # a ConnectionError here is expected\n            return\n        raise RedisError(\"SHUTDOWN seems to have failed.\")\n","sourceCodeStart":2094,"sourceCodeEnd":2130,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L2094-L2130","documentation":"Raised by shutdown when both save=True and nosave=True are passed simultaneously. These flags are contradictory — save forces a DB dump on shutdown, nosave suppresses it — so the client rejects the combination before sending anything to the server.","triggerScenarios":"Calling r.shutdown(save=True, nosave=True). Building shutdown args dynamically where both flags resolve True. Copy-pasting a config that set both as a 'cover all cases' pattern.","commonSituations":"Config file maps two independent booleans that both default True. Migration from a system where one flag was ignored. Defensive code that sets both flags 'just in case'.","solutions":["Set exactly one of save or nosave (or neither for server-default behavior).","Guard dynamic flags: if save and nosave: raise in your own code before calling.","Use save=True to force persistence, nosave=True to skip it; never both."],"exampleFix":"# before\nr.shutdown(save=True, nosave=True)\n# after\nr.shutdown(save=True)","handlingStrategy":"validation","validationCode":"if save and nosave:\n    raise ValueError('shutdown: save and nosave are mutually exclusive')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat save and nosave as mutually exclusive shutdown modifiers.","Validate config-derived flags before passing to shutdown."],"tags":["server-management","validation","shutdown","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}