# LMOVE

> Pop an element from one list and push it onto another, atomically.

URL: https://docs.hotkv.com/commands/lmove/

```
LMOVE source destination LEFT | RIGHT LEFT | RIGHT
```

- Group: List
- Complexity: O(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](https://docs.hotkv.com/commands/blmove/index.md).

## 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

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

## Examples

```
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"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[BLMOVE](https://docs.hotkv.com/commands/blmove/index.md), [RPOPLPUSH](https://docs.hotkv.com/commands/rpoplpush/index.md), [LPOP](https://docs.hotkv.com/commands/lpop/index.md),
[RPUSH](https://docs.hotkv.com/commands/rpush/index.md), [LMPOP](https://docs.hotkv.com/commands/lmpop/index.md)