Copied!
Node
Redis

Best Guide to Using Redis Lists in Node.js

redis-lists-in-node.js
Shahroz Javed
Nov 04, 2025 . 28 views

Table Of Contents

 

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.

💡 Related: Check our Redis Basics Guide for Node.js Developers to understand fundamental Redis commands.

Install Redis for Node.js

First, install the official Redis client using npm:

npm install redis
    

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:

🧠 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 List Example Output
Console output showing Redis list operations in action

Conclusion

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.

✅ Tip: Always close your Redis client using client.quit() after completing operations to free up resources.

15 Shares

Similar Posts