redis/redis-py · error · DataError
XCFGSET idmp_duration must be an integer between 1 and 300
Error message
XCFGSET idmp_duration must be an integer between 1 and 300
What it means
Raised by xcfgset() when idmp_duration is provided but is not an int, or is outside [1, 300]. This is the Redis stream-idmp-duration bound; the library enforces it client-side via a strict isinstance(int) check (so floats/strings fail; bool sneaks through because bool subclasses int).
Source
Thrown at redis/commands/core.py:7122
Returns:
OK on success.
For more information, see https://redis.io/commands/xcfgset
"""
if idmp_duration is None and idmp_maxsize is None:
raise DataError(
"XCFGSET requires at least one of idmp_duration or idmp_maxsize"
)
pieces: list[EncodableT] = []
if idmp_duration is not None:
if (
not isinstance(idmp_duration, int)
or idmp_duration < 1
or idmp_duration > 300
):
raise DataError(
"XCFGSET idmp_duration must be an integer between 1 and 300"
)
pieces.extend([b"IDMP-DURATION", idmp_duration])
if idmp_maxsize is not None:
if (
not isinstance(idmp_maxsize, int)
or idmp_maxsize < 1
or idmp_maxsize > 1000000
):
raise DataError(
"XCFGSET idmp_maxsize must be an integer between 1 and 1,000,000"
)
pieces.extend([b"IDMP-MAXSIZE", idmp_maxsize])
return self.execute_command("XCFGSET", name, *pieces)
@overloadView on GitHub (pinned to da03cdc7e8)
Solutions
- Pass an int between 1 and 300 inclusive.
- If the value comes from config, coerce and clamp: v = max(1, min(300, int(raw))).
- If you need to disable idempotency tracking, do not pass IDMP-DURATION at all (set only maxsize, or drop XCFGSET).
Example fix
# before
r.xcfgset('s', idmp_duration=config['idle_secs']) # '30' str -> fails
# after
r.xcfgset('s', idmp_duration=max(1, min(300, int(config['idle_secs'])))) Defensive patterns
Strategy: validation
Validate before calling
def xcfg_duration(raw):
v = int(raw)
if not 1 <= v <= 300:
raise ValueError(f'idmp_duration out of range: {v}')
return v
r.xcfgset(name, idmp_duration=xcfg_duration(raw)) Try / catch
from redis.exceptions import DataError
try:
r.xcfgset(name, idmp_duration=v)
except DataError:
v = max(1, min(300, int(v))); r.xcfgset(name, idmp_duration=v) Prevention
- Coerce env/YAML values with int() before passing.
- Remember the floor is 1, not 0.
When it happens
Trigger: xcfgset(name, idmp_duration=0), =301, =3.5 (float), ='100' (str), =-5. Check at core.py:7117-7124: `not isinstance(idmp_duration, int) or <1 or >300`.
Common situations: Reading duration from YAML/env as a string; computing a float seconds value; off-by-one on the 300s ceiling; using -1 / 0 as a 'disable' sentinel (the minimum is 1, not 0).
Related errors
- XCFGSET idmp_maxsize must be an integer between 1 and 1,000,
- XCFGSET requires at least one of idmp_duration or idmp_maxsi
- XAUTOCLAIM min_idle_time must be a nonnegative integer
- XPENDING count must be a integer >= 0
- XNACK retrycount must be >= 0
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/a4606f91a9f0e089.json.
Report an issue: GitHub.