Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

LMOVE

Last updated
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.

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.
Case RESP2 RESP3
Moved Bulk string: the element that was moved Same
source does not exist Nil bulk string Null

Errors:

  • ERR syntax error if a direction is not LEFT or RIGHT.
  • WRONGTYPE if source holds a value that is not a list, or destination exists and is not a list. Nothing is moved in that case.
127.0.0.1:6379> RPUSH jobs:pending j1 j2 j3
(integer) 3
127.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 -1
1) "j3"
2) "j2"
127.0.0.1:6379> LRANGE jobs:active 0 -1
1) "j1"

Same as Redis 7.4 and Valkey 8.

BLMOVE, RPOPLPUSH, LPOP, RPUSH, LMPOP