Redis Lists are one of the most useful data types for queue-like operations and ordered data storage. In this post, you’ll learn how to use Redis Lists in Node.js to push, retrieve, and pop items efficiently.
⚠️ Note: Make sure Redis is installed and running locally before executing the commands below. Default Redis URL is redis://127.0.0.1:6379.
Introduction
A Redis List is an ordered collection of strings. You can think of it like an array that allows fast insertion and removal from both ends. It’s commonly used for queues, task lists, or message buffers.
- LPUSH / RPUSH — add items to the left or right of a list.
- LPOP / RPOP — remove items from the left or right.
- LRANGE — fetch a range of items from the list.
Install Redis for Node.js
First, install the official Redis client using npm:
Then import and connect to Redis inside your Node.js project.
Working with Redis Lists
Below is a complete example showing how to push, retrieve, and pop list items in Redis using the official client:
import { createClient } from "redis";
const client = createClient();
await client.connect();
// Push items into list
await client.rPush("tasks", "Task 1");
await client.rPush("tasks", "Task 2");
await client.lPush("tasks", "Task 0"); // Push from left
// Get all list items
const tasks = await client.lRange("tasks", 0, -1);
console.log("Tasks:", tasks);
// Pop from list (queue behavior)
const firstTask = await client.lPop("tasks");
console.log("Processing:", firstTask);
await client.quit();
The above example demonstrates basic queue-like operations:
rPush adds tasks at the end of the list.
lPush adds a task to the beginning.
lRange retrieves all items from the list.
lPop removes the first task (similar to dequeue).
🧠 Tip: Lists are perfect for task queues where you insert jobs at one end and process them from the other.
Example Output
When you run the script, you’ll see an output like this:
Tasks: [ 'Task 0', 'Task 1', 'Task 2' ]
Processing: Task 0
Redis Lists make it easy to implement queues, stacks, and ordered data structures directly in memory. With just a few commands, you can manage tasks, process jobs, or maintain activity logs in real time.