redis/redis-py · error · DataError

idletimemust be an integer

Error message

idletimemust be an integer

What it means

Raised as a `DataError` by `restore()` (redis/commands/core.py:4280) when `int(idletime)` raises `ValueError`, i.e. `idletime` is provided but cannot be parsed as an integer. (Note the literal message has a typo: 'idletimemust be an integer' with no space.) RESTORE's IDLETIME eviction hint must be an integer number of seconds.

Solutions

  1. Pass an integer for `idletime`.
  2. Coerce and validate before calling: `idletime = int(idletime)`.
  3. If the source is a float string, parse with `float()` then `int()`.

Example fix

// before
r.restore('k', 0, blob, idletime='1.5')
// after
r.restore('k', 0, blob, idletime=int(float('1.5')))
Defensive patterns

Strategy: type-guard

Validate before calling

if idletime is not None:
    idletime = int(idletime)  # raises ValueError early if non-integer
r.restore('k', 0, blob, idletime=idletime)

Type guard

def is_intlike(v) -> bool:
    try:
        int(v)
        return True
    except (TypeError, ValueError):
        return False

Prevention

When it happens

Trigger: `r.restore('k', 0, blob, idletime='abc')`, `r.restore('k', 0, blob, idletime=1.5)` (float string that int() rejects is fine for '1.5'? int('1.5') raises ValueError), or any non-int-coercible value.

Common situations: Passing a float (1.5) which `int()` accepts as 1 but a float *string* ('1.5') which it rejects; user/JSON input typed as string; copying a frequency-style string into idletime.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/ca033ae6cf69f45e. Report an issue: GitHub.

Appendix: source

Thrown at redis/commands/core.py:4280

        ``idletime`` Used for eviction, this is the number of seconds the
        key must be idle, prior to execution.

        ``frequency`` Used for eviction, this is the frequency counter of
        the object stored at the key, prior to execution.

        For more information, see https://redis.io/commands/restore
        """
        params = [name, ttl, value]
        if replace:
            params.append("REPLACE")
        if absttl:
            params.append("ABSTTL")
        if idletime is not None:
            params.append("IDLETIME")
            try:
                params.append(int(idletime))
            except ValueError:
                raise DataError("idletimemust be an integer")

        if frequency is not None:
            params.append("FREQ")
            try:
                params.append(int(frequency))
            except ValueError:
                raise DataError("frequency must be an integer")

        return self.execute_command("RESTORE", *params)

    @overload
    def set(
        self: SyncClientProtocol,
        name: KeyT,
        value: EncodableT,
        ex: ExpiryT | None = ...,
        px: ExpiryT | None = ...,
        nx: bool = ...,

View on GitHub (pinned to 6a6b581b48)