redis/redis-py · error · ValueError
Both ignore_max_time_diff and ignore_max_val_diff must be se
Error message
Both ignore_max_time_diff and ignore_max_val_diff must be set.
What it means
Raised by _append_insertion_filters (used by TS.ADD, TS.MADD, TS.INCRBY, TS.DECRBY) when only one of ignore_max_time_diff / ignore_max_val_diff is set. The IGNORE clause requires both a time threshold and a value threshold together; they are not independently optional. Note this raises ValueError (not DataError).
Source
Thrown at redis/commands/timeseries/commands.py:2137
"""Append EMPTY property to params."""
if empty:
params.append("EMPTY")
@staticmethod
def _append_exclude_empty(params: list[EncodableT], exclude_empty: bool | None):
"""Append EXCLUDEEMPTY property to params."""
if exclude_empty:
params.append("EXCLUDEEMPTY")
@staticmethod
def _append_insertion_filters(
params: list[EncodableT],
ignore_max_time_diff: int | None = None,
ignore_max_val_diff: Number | None = None,
):
"""Append insertion filters to params."""
if (ignore_max_time_diff is None) != (ignore_max_val_diff is None):
raise ValueError(
"Both ignore_max_time_diff and ignore_max_val_diff must be set."
)
if ignore_max_time_diff is not None and ignore_max_val_diff is not None:
params.extend(
["IGNORE", str(ignore_max_time_diff), str(ignore_max_val_diff)]
)
View on GitHub (pinned to da03cdc7e8)
Solutions
- Set both thresholds together: client.ts().add('key', '*', 1.0, ignore_max_time_diff=100, ignore_max_val_diff=0.5).
- If you do not want the IGNORE clause, omit both arguments.
- Note this also requires duplicate_policy='last' server-side for the IGNORE to take effect.
Example fix
// before
client.ts().add('key', '*', 1.0, ignore_max_time_diff=100)
// after
client.ts().add('key', '*', 1.0, duplicate_policy='last', ignore_max_time_diff=100, ignore_max_val_diff=0.5) Defensive patterns
Strategy: validation
Validate before calling
def normalize_ignore(time_diff, val_diff):
if (time_diff is None) != (val_diff is None):
raise ValueError("Set both ignore_max_time_diff and ignore_max_val_diff, or neither")
return time_diff, val_diff Type guard
def ignore_pair_valid(time_diff, val_diff) -> bool:
return (time_diff is None) == (val_diff is None) Try / catch
try:
client.ts().add('k', '*', 1.0, ignore_max_time_diff=td)
except ValueError:
client.ts().add('k', '*', 1.0) # drop the IGNORE clause Prevention
- Always set both ignore thresholds together or omit both.
- Remember IGNORE also needs duplicate_policy='last' server-side.
- Validate the pair in a helper before TS.ADD/MADD/INCRBY/DECRBY.
When it happens
Trigger: client.ts().add('key', '*', 1.0, ignore_max_time_diff=100) without ignore_max_val_diff, or the reverse. Both thresholds must be present.
Common situations: Enabling the ignore-duplicate threshold for one dimension only; reading thresholds from config where one is missing; assuming the value threshold defaults.
Related errors
- At least one key must be provided.
- GROUPBY is not allowed when multiple aggregators are specifi
- EXCLUDEEMPTY is not allowed with GROUPBY
- filters cannot be an empty collection; pass None to query al
- with_labels and select_labels cannot be provided together.
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/635f9eb5d843027f.json.
Report an issue: GitHub.