How to add multiple elements?

You can add multiple elements to a Redis list using the LPUSH command by specifying additional values after the key. Here’s the syntax:

Syntax

LPUSH key value1 value2 [value3 ...]

Example

To add multiple items to a list named todo_list, you can use the following command:

LPUSH todo_list "Grocery Shopping" "Laundry" "Homework"

In this example, "Grocery Shopping", "Laundry", and "Homework" will be added to the beginning of the todo_list. If you check the list afterward using LRANGE todo_list 0 -1, you will see these items in the order they were added, with "Homework" at the front.

0 Comments

no data
Be the first to share your comment!