redis/redis · error
Options -4 and -6 are mutually exclusive.
Error message
Options -4 and -6 are mutually exclusive.
What it means
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.
Source
Thrown at src/redis-cli.c:3153
}
if (!config.no_auth_warning && config.conn_info.auth != NULL) {
fputs("Warning: Using a password with '-a' or '-u' option on the command"
" line interface may not be safe.\n", stderr);
}
if (config.get_functions_rdb_mode && config.getrdb_mode) {
fprintf(stderr,"Option --functions-rdb and --rdb are mutually exclusive.\n");
exit(1);
}
if (config.stdin_lastarg && config.stdin_tag_arg) {
fprintf(stderr, "Options -x and -X are mutually exclusive.\n");
exit(1);
}
if (config.prefer_ipv4 && config.prefer_ipv6) {
fprintf(stderr, "Options -4 and -6 are mutually exclusive.\n");
exit(1);
}
return i;
}
static void parseEnv(void) {
/* Set auth from env, but do not overwrite CLI arguments if passed */
char *auth = getenv(REDIS_CLI_AUTH_ENV);
if (auth != NULL && config.conn_info.auth == NULL) {
config.conn_info.auth = auth;
}
char *cluster_yes = getenv(REDIS_CLI_CLUSTER_YES_ENV);
if (cluster_yes != NULL && !strcmp(cluster_yes, "1")) {
config.cluster_manager_command.flags |= CLUSTER_MANAGER_CMD_FLAG_YES;
}
}View on GitHub (pinned to 4f20cb4893)
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.
Example fix
// before redis-cli -4 -6 -h myhost PING // after redis-cli -4 -h myhost PING
Defensive patterns
Strategy: validation
Validate before calling
# Reject mutually-exclusive -4/-6 before launching redis-cli
args=("$@")
has4=0; has6=0
for a in "${args[@]}"; do
case "$a" in -4) has4=1;; -6) has6=1;; esac
done
if [[ $has4 -eq 1 && $has6 -eq 1 ]]; then
echo "Error: -4 and -6 are mutually exclusive" >&2; exit 2
fi
exec redis-cli "$@" Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Using -X option but stdin tag not match.
- [ERR] Wrong number of arguments for specified --cluster sub
- Unknown --cluster subcommand
- Error: invalid CLUSTER NODES reply
- Invalid address format: %s
AI-assisted analysis of redis/redis@4f20cb4893 (2026-08-10).
Data as JSON: /api/errors/673ac760af5c4390.
Report an issue: GitHub.