Introduction
Lists keep items in order, just like a line of people waiting. This helps you remember the exact order things were added.
Lists keep items in order, just like a line of people waiting. This helps you remember the exact order things were added.
LPUSH key value [value ...] RPUSH key value [value ...] LRANGE key start stop
LPUSH adds items to the start (left) of the list.
RPUSH adds items to the end (right) of the list.
LPUSH tasks "task1" LPUSH tasks "task2" LRANGE tasks 0 -1
RPUSH songs "song1" RPUSH songs "song2" LRANGE songs 0 -1
LRANGE emptylist 0 -1
This adds three fruits to the list in order and then gets all items to show the order is kept.
RPUSH mylist "apple" RPUSH mylist "banana" RPUSH mylist "cherry" LRANGE mylist 0 -1
Lists keep the order of items exactly as added.
Adding to the left or right changes where new items appear.
Lists are good for queues and stacks because order matters.
Lists store items in the order you add them.
You can add items to the start or end to control order.
Use lists when order of data is important.
RPUSH mylist ALPUSH mylist BRPUSH mylist CLRANGE mylist 0 -1 return?LPUSH mylist XRPUSH mylist YLPOP mylistPass the test and this pattern moves unknown