Redis Lists: LPUSH
Redis LPUSH Command
Redis LPUSH command is used to insert all the specified values at the head of the list stored at key. It is created as an empty list before performing the push operations if tje key does not exist. When key holds a value that is not a list, an error is returned.
Here are some common uses and scenarios for the "LPUSH" command:
- Queue Operations: Prepend elements to a list to manage tasks or messages in a queue.
- Task Management: Prioritize tasks by adding them to the front of a queue.
- Event Handling: Insert events or messages at the beginning of a list for immediate processing.
- Data Processing Pipelines: Build data pipelines by pushing data to the front of a list for subsequent processing stages.
- Stack Operations: Implement a last-in, first-out (LIFO) stack by pushing elements onto a list.
Syntax:
LPUSH KEY_NAME VALUE1.. VALUEN
Available since
1.0.0.
Return Value
Integer replies the length of the list after the push operations.
Return Value Type
Integer
Example: Redis LPUSH
127.0.0.1:6379> LPUSH mycolor1 white black (integer) 2 127.0.0.1:6379> LRANGE mycolor1 0 -1 1) "black" 2) "white" 127.0.0.1:6379> LPUSH mycolor1 red blue (integer) 4 127.0.0.1:6379> LRANGE mycolor1 0 -1 1) "blue" 2) "red" 3) "black" 4) "white"
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/redis/redis-lpush-key-value1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics