redis/redis-py · error · DataError
frequency must be an integer
Error message
frequency must be an integer
What it means
Raised as a `DataError` by `restore()` (redis/commands/core.py:4286) when `int(frequency)` raises `ValueError`, i.e. `frequency` is provided but is not integer-coercible. RESTORE's FREQ eviction counter must be an integer.
Solutions
- Pass an integer for `frequency`.
- Validate/coerce before calling: `frequency = int(frequency)`.
- Guard against None — frequency is optional and should be omitted, not passed as a string, when unused.
Example fix
// before
r.restore('k', 0, blob, frequency='5')
// after
r.restore('k', 0, blob, frequency=int('5')) Defensive patterns
Strategy: type-guard
Validate before calling
if frequency is not None:
frequency = int(frequency)
r.restore('k', 0, blob, frequency=frequency) Type guard
def is_intlike(v) -> bool:
try:
int(v)
return True
except (TypeError, ValueError):
return False Prevention
- Coerce frequency to int before calling.
- Omit frequency entirely (None) when unused.
When it happens
Trigger: `r.restore('k', 0, blob, frequency='high')`, `r.restore('k', 0, blob, frequency='2.7')`, or any non-int value for frequency.
Common situations: Deserialized frequency values typed as strings; passing a labeled/enum frequency instead of its numeric counter; user input not sanitized.
Related errors
- idletimemust be an integer
- bit must be 0 or 1
- Both start and end must be specified
- ``byfloat`` and ``byint`` are mutually exclusive.
- ``count`` is required when ``mode`` or ``ordering`` is set
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/551761017d40cefa.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/core.py:4287
"""
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 = ...,
xx: bool = ...,
keepttl: bool = ...,
get: bool = ...,
exat: AbsExpiryT | None = ...,
pxat: AbsExpiryT | None = ...,
ifeq: bytes | str | None = ...,
ifne: bytes | str | None = ...,View on GitHub (pinned to 6a6b581b48)