Redis List Management: Guide to Adding, Reading and Deleting Data
What will you learn in this guide?
This guide explains the Redis List data type with practical examples.
Teaches adding, reading, updating and deleting data to the list.
Clarifies queue and stack scenarios.
🧠 Technical Summary
Main topic: Redis List data structure.
Solved problem: Managing sequential data in insertion order.
Steps: Creating a list → reading data → deleting → moving between lists.
1. Creating a list and adding elements
Redis lists maintain append order.
Elements can be added to the beginning or end.
lpush tr1_liste "Merhaba"
- This command adds the data to the beginning of the list.
rpush tr1_liste "Dunya"
- This command adds the data to the end of the list.
- Multiple elements can be added in a single command.
rpush tr1_liste "Redis" "List" "Ornek"
- This command adds multiple data at once.
2. Conditional addition to existing list
- If there is no list, LPUSHX and RPUSHX are used to avoid adding.
rpushx tr1_liste "YeniVeri"
- If there is no list, no action is taken and 0 is returned.
3. Update element in list
- LSET is used to change the data at a particular index.
lset tr1_liste 0 "Selam"
- This command updates the value at index 0.
4. Reading data from list
- LRANGE is used to get a specific range.
lrange tr1_liste 0 -1
- This command retrieves all elements in the list.
To get the last three elements:
lrange tr1_liste -3 -1
- This command reads data from the end.
LINDEX is used for a single element.
lindex tr1_liste 1
- This command returns the data at the specified index.
5. Find out list length
llen tr1_liste
- This command returns the number of elements in the list.
6. Delete data from the list
- LREM is used to delete a specific value.
lrem tr1_liste 2 "Merhaba"
- This command deletes the first two matches.
To retrieve and delete data from the beginning:
lpop tr1_liste
- To get data from the end:
rpop tr1_liste
7. Moving data between lists
- To move the data at the end of one list to the beginning of another list:
rpoplpush kaynak_liste hedef_liste
- This command performs migration without data loss.
If the source and destination are the same, the list is returned.
Frequently Asked Questions (FAQ)
1. What is the difference between Redis List and Set? Lists are ordered and contain repeating elements. The set structure is unordered and stores unique elements.
2. What does negative index do? It allows counting from the end. -1 represents the last element, -2 represents the second to last element.
3. What happens if a key is not a list? Redis returns a WRONGTYPE error. Data type conversion is not done automatically.
4. Where are Redis lists used? Used in queuing systems, log streams and task lists.
Result
Redis List data type is ideal for sequential data management. Queue and stack scenarios are easily implemented. Correct commands provide high performance.
You can try Redis-based scalable infrastructures on the GenixNode platform now.

