redis/redis-py · error · DataError
``count`` is required when ``mode`` or ``ordering`` is set
Error message
``count`` is required when ``mode`` or ``ordering`` is set
What it means
Raised as a `DataError` by `lmovem()` (redis/commands/core.py:3671) when `count` is `None` but `mode` or `ordering` is supplied. LMOVEM's multi-element mode is only meaningful together with a count; specifying mode/ordering without a count is rejected.
Solutions
- When you set `mode` or `ordering`, also pass `count` (a positive int).
- Drop `mode`/`ordering` for single-element moves (no count).
- Treat count, mode, and ordering as a single resolved group before calling.
Example fix
// before
r.lmovem('src', 'dst', mode='EXACTLY')
// after
r.lmovem('src', 'dst', count=3, mode='EXACTLY', ordering='BULK') Defensive patterns
Strategy: validation
Validate before calling
if count is None and (mode is not None or ordering is not None):
raise ValueError('lmovem: count is required when mode/ordering is set')
r.lmovem('a', 'b', count=count, mode=mode, ordering=ordering) Prevention
- Bundle (count, mode, ordering) as one optional group.
- Omit all three for a single-element move.
When it happens
Trigger: `r.lmovem('a', 'b', mode='EXACTLY')`, `r.lmovem('a', 'b', ordering='BULK')`, or any LMOVEM call that sets mode/ordering but omits count.
Common situations: Building kwargs conditionally and setting mode/ordering in a branch that forgot count; assuming defaults fill in count; experimental API (LMOVEM is new).
Related errors
- ``ordering`` (OBO or BULK) is required when ``count`` is set
- bit must be 0 or 1
- Both start and end must be specified
- ``byfloat`` and ``byint`` are mutually exclusive.
- ``enx`` requires one of ``ex``, ``px``, ``exat``, or…
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/2cd86443d1a4b1a8.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/core.py:3672
``LEFT`` (head) or ``RIGHT`` (tail).
When ``count`` is given, ``mode`` selects how many elements to move:
``COUNT`` (the default) moves up to ``count`` elements, while
``EXACTLY`` moves exactly ``count`` elements or nothing at all. When
``count`` is not given a single element is moved.
``ordering`` controls the order at the destination: ``OBO`` pushes each
element as it is popped (reversing block order, stack semantics) while
``BULK`` preserves the original relative order (queue semantics). It is
required whenever ``count`` is given.
Returns the array of moved elements, or ``None`` if nothing was moved.
For more information, see https://redis.io/commands/lmovem
"""
if count is None:
if mode is not None or ordering is not None:
raise DataError(
"``count`` is required when ``mode`` or ``ordering`` is set"
)
elif ordering is None:
raise DataError(
"``ordering`` (OBO or BULK) is required when ``count`` is set"
)
pieces: list[EncodableT] = [first_list, second_list, src, dest]
if count is not None:
pieces.extend([mode or "COUNT", count, ordering])
return self.execute_command("LMOVEM", *pieces)
@overload
def blmovem(
self: SyncClientProtocol,
first_list: str,
second_list: str,
timeout: float,
src: str = "LEFT",View on GitHub (pinned to 6a6b581b48)