LMOVE
LMOVE source destination LEFT | RIGHT LEFT | RIGHT
- Group
- List
- Complexity
- O(1)
- Arity
- 5 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
LMOVE removes an element from one end of the list at source and pushes it
onto one end of the list at destination, as a single atomic step. The first
LEFT | RIGHT picks the end of source to pop from; the second picks the end
of destination to push to. destination is created if it does not exist,
and source is deleted when its last element leaves.
source and destination can be the same key. LMOVE key key LEFT RIGHT
rotates the list, moving its first element to the end.
A reliable-queue pattern uses LMOVE to move a job from a pending list to a
processing list, so the job is not lost if the worker crashes before it
finishes. To wait for an element, use BLMOVE.
Options
Section titled “Options”| Option | Effect |
|---|---|
LEFT (first) |
Pop from the head of source. |
RIGHT (first) |
Pop from the tail of source. |
LEFT (second) |
Push onto the head of destination. |
RIGHT (second) |
Push onto the tail of destination. |
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Moved | Bulk string: the element that was moved | Same |
source does not exist |
Nil bulk string | Null |
Errors:
ERR syntax errorif a direction is notLEFTorRIGHT.WRONGTYPEifsourceholds a value that is not a list, ordestinationexists and is not a list. Nothing is moved in that case.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH jobs:pending j1 j2 j3(integer) 3127.0.0.1:6379> LMOVE jobs:pending jobs:active LEFT RIGHT"j1"127.0.0.1:6379> LMOVE jobs:pending jobs:pending LEFT RIGHT"j2"127.0.0.1:6379> LRANGE jobs:pending 0 -11) "j3"2) "j2"127.0.0.1:6379> LRANGE jobs:active 0 -11) "j1"Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.