{"record":{"id":"673ac760af5c4390","repo":"redis/redis","slug":"options-4-and-6-are-mutually-exclusive","errorCode":null,"errorMessage":"Options -4 and -6 are mutually exclusive.\n","messagePattern":"Options -4 and -6 are mutually exclusive\\.\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/redis-cli.c","lineNumber":3153,"sourceCode":"    }\n\n    if (!config.no_auth_warning && config.conn_info.auth != NULL) {\n        fputs(\"Warning: Using a password with '-a' or '-u' option on the command\"\n              \" line interface may not be safe.\\n\", stderr);\n    }\n\n    if (config.get_functions_rdb_mode && config.getrdb_mode) {\n        fprintf(stderr,\"Option --functions-rdb and --rdb are mutually exclusive.\\n\");\n        exit(1);\n    }\n \n    if (config.stdin_lastarg && config.stdin_tag_arg) {\n        fprintf(stderr, \"Options -x and -X are mutually exclusive.\\n\");\n        exit(1);\n    }\n\n    if (config.prefer_ipv4 && config.prefer_ipv6) {\n        fprintf(stderr, \"Options -4 and -6 are mutually exclusive.\\n\");\n        exit(1);\n    }\n\n    return i;\n}\n\nstatic void parseEnv(void) {\n    /* Set auth from env, but do not overwrite CLI arguments if passed */\n    char *auth = getenv(REDIS_CLI_AUTH_ENV);\n    if (auth != NULL && config.conn_info.auth == NULL) {\n        config.conn_info.auth = auth;\n    }\n\n    char *cluster_yes = getenv(REDIS_CLI_CLUSTER_YES_ENV);\n    if (cluster_yes != NULL && !strcmp(cluster_yes, \"1\")) {\n        config.cluster_manager_command.flags |= CLUSTER_MANAGER_CMD_FLAG_YES;\n    }\n}","sourceCodeStart":3135,"sourceCodeEnd":3171,"githubUrl":"https://github.com/redis/redis/blob/4f20cb48934463db5970bd476461b2d57af3f38d/src/redis-cli.c#L3135-L3171","documentation":"redis-cli refuses to start when both the -4 (prefer IPv4) and -6 (prefer IPv6) flags are given together. The flags drive anet's address-family preference used for DNS resolution and socket connection, and they are logically contradictory, so the option parser rejects the combination and exits with status 1 at startup. It is purely an argument-validation guard emitted before any connection is attempted.","triggerScenarios":"Invoking redis-cli with both flags on one command line, e.g. `redis-cli -4 -6 -h myhost PING`. The guard at redis-cli.c:3152-3155 fires because config.prefer_ipv4 and config.prefer_ipv6 are both set.","commonSituations":"Copy-pasted flag combos merged from two runbooks; a shell alias or wrapper script that always appends `-4` colliding with an operator who adds `-6` for an IPv6-only host; dual-stack migration where both preferences were left enabled.","solutions":["Pass only one of -4 or -6; omit both to let the OS/hiredis choose the default family.","Inspect aliases and wrappers for stale flags: run `alias redis-cli` / `type redis-cli` and grep your launcher script.","If the choice must be environment-specific, set it once in a config/env file rather than per-invocation."],"exampleFix":"// before\nredis-cli -4 -6 -h myhost PING\n// after\nredis-cli -4 -h myhost PING","handlingStrategy":"validation","validationCode":"# Reject mutually-exclusive -4/-6 before launching redis-cli\nargs=(\"$@\")\nhas4=0; has6=0\nfor a in \"${args[@]}\"; do\n  case \"$a\" in -4) has4=1;; -6) has6=1;; esac\ndone\nif [[ $has4 -eq 1 && $has6 -eq 1 ]]; then\n  echo \"Error: -4 and -6 are mutually exclusive\" >&2; exit 2\nfi\nexec redis-cli \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep address-family preference in a single place (env var or alias), never per-invocation on both flags.","Lint wrapper scripts to reject simultaneous -4 and -6."],"tags":["redis-cli","arguments","ipv","configuration","startup"],"backgroundTag":null,"analyzedSha":"4f20cb48934463db5970bd476461b2d57af3f38d","analyzedAt":"2026-08-10T14:17:07.821Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}