lpop
LPOP
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Pop a value from the left of the list
Pops a value from the left of the list. It is removed from the list.
Example
| Command> | lpush mylist value1 value2 value3 value4 |
| Result> | 4 |
| Command> | lrange mylist 0 -1 |
| Result> | 0) value4 1) value3 2) value2 3) value1 |
| Command> | lpop mylist |
| Result> | value4 |
| Command> | lrange mylist 0 -1 |
| Result> | 0) value3 1) value2 2) value1 |
| Command> | lpop mylist |
| Result> | value3 |
When used as a queue
A queue is used to process data in time order.
The first received data is processed first. Use LPUSH and RPOP.
Example: Queue
| Command> | lpush mylist msg_1 msg_2 |
| Result> | 2 |
| Command> | lpush mylist msg_3 msg_4 |
| Result> | 4 |
| Command> | lrange mylist 0 -1 |
| Result> | 0) msg_4 1) msg_3 2) msg_2 3) msg_1 |
| Command> | rpop mylist |
| Result> | msg_4 |
| Command> | rpop mylist |
| Result> | msg_3 |
When used as a stack
A stack is used to process data in reverse time order.
The last received data is processed first. Use LPUSH and LPOP.
Example: Stack
| Command> | lpush mylist msg_1 msg_2 |
| Result> | 2 |
| Command> | lpush mylist msg_3 msg_4 |
| Result> | 4 |
| Command> | lrange mylist 0 -1 |
| Result> | 0) msg_4 1) msg_3 2) msg_2 3) msg_1 |
| Command> | lpop mylist |
| Result> | msg_1 |
| Command> | lpop mylist |
| Result> | msg_2 |
Pop multiple values: COUNT option
To pop multiple values, use the COUNT option.
The Count option is available since version 6.2.
Example: Count
| Command> | lpush mylist value1 value2 value3 value4 |
| Result> | 4 |
| Command> | lpop mylist 3 |
| Result> |
1) value4 2) value3 3) value2 |
Syntax
LPOP key [count]
- Available since version 1.0.0.
- Time complexity is O(N). N is the number of returned values.
- The COUNT option was added in version 6.2.
| Related commands | RPOP, LPUSH, RPUSH |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << RPOP | LPOP | RPUSH >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
