{"record":{"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/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L2094-L2130","documentation":"Raised by shutdown() (redis/commands/core.py:2112) when both save=True and nosave=True are passed. The two flags are contradictory at the protocol level (SAVE forces a dump, NOSAVE skips it), so the library rejects the combination before sending. This is a redis.exceptions.DataError raised client-side. The other flags (now, force, abort) are independent.","triggerScenarios":"Calling r.shutdown(save=True, nosave=True); or building flags from config where both accidentally resolve to True (e.g. inverted boolean logic).","commonSituations":"Mistakenly toggling both booleans; or a config schema that allows both to be set and forwards them straight through.","solutions":["Choose one: r.shutdown(save=True) to force a dump, or r.shutdown(nosave=True) to skip it","If both come from config, enforce mutual exclusivity upstream and default the other to False","Leave both False (the default) to honor the server's configured save points"],"exampleFix":"# before\nr.shutdown(save=True, nosave=True)\n# after\nr.shutdown(save=True)","handlingStrategy":"validation","validationCode":"if save and nosave:\n    raise ValueError(\"save and nosave are mutually exclusive\")\nr.shutdown(save=save, nosave=nosave, now=now, force=force, abort=abort)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r.shutdown(save=s, nosave=n)\nexcept DataError as e:\n    if \"save and nosave cannot both be set\" in str(e):\n        r.shutdown(save=s)  # resolve conflict by preferring save\n    else:\n        raise","preventionTips":["Treat save/nosave as mutually exclusive radio options in config.","Validate the pair at the config boundary, not at the call site.","Default both to False to honor the server's own save policy."],"tags":["admin","validation","dataerror","shutdown"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}