New from O’Reilly: The memory architecture behind adaptive AI agents

Read the report
For developersGetting Started with Node and Redis
Ajeet Raina
Ajeet Raina
Simon Prickett
Simon Prickett

Find tutorials, examples and technical articles that will help you to develop with Redis and Node.js/JavaScript:

Introduction

Redis is an open source, in-memory, key-value data store most commonly used as a primary database, cache, message broker, and queue. Redis cache delivers sub-millisecond response times, enabling fast and powerful real-time applications in industries such as gaming, fintech, ad-tech, social media, healthcare, and IoT.

Redis is a great database for use with Node. Both Redis and Node share similar type conventions and threading models, which makes for a very predictable development experience. By pairing Node and Redis together you can achieve a scalable and productive development platform.

Redis has two primary Node clients which are node-redis and ioredis. Both are available through npm. We generally suggest using node-redis, as it has wide support for Redis modules, is easily extended, and is widely used.

Check out a list of Redis clients that the community has built for Node here.

This article shows how to get started with the recommended libraries: node-redis and ioredis.

node-redis

Step 1. Run a Redis server

You can either run Redis in a Docker container or directly on your Mac OS. Use the following commands to setup a Redis server locally:

INFO

Redis Stack unifies and simplifies the developer experience of the leading Redis data store, modules and the capabilities they provide. Redis Stack supports the folliwng in additon to Redis: JSON, Search, Time Series, Triggers and Functions, and Probilistic data structures.

Ensure that you are able to use the following Redis command to connect to the Redis instance.

Now you should be able to perform CRUD operations with Redis keys. The above Redis client command might require password if you have setup authentication in your Redis configuration file. Refer Redis Command Reference

Step 2. Install node redis using **NPM** (or **YARN**)

Run the following NPM command to install the Redis client.

Step 3. Write your Application Code​

Use the following sample code for our Node.js application:

ioredis

Step 1. Install **ioredis** using **npm** (or **yarn**)

Step 2. Write your Application Code

Redis Launchpad

Redis Launchpad is like an “App Store” for Redis sample apps. You can easily find apps for your preferred frameworks and languages. Check out a few of these apps below, or click here to access the complete list.

Hacker News Clone in NodeJS

Image

A Hacker News Clone project built in NextJS, NodeJS and Express based on Search and JSON


Shopping Cart application in NodeJS

Image

Shopping Cart app in NodeJS module functionalities

More Developer Resources

Sample Code

Basic Redis Caching This application calls the GitHub API and caches the results into Redis.

Redis Rate-Limiting This is a very simple app that demonstrates rate-limiting feature using Redis.

Notifications with WebSocket, Vue & Redis This project allows you to push notifications in a Vue application from a Redis PUBLISH using WebSockets.

Technical Articles & Videos

Redis Rapid Tips: ioredis (YouTube)

Mapping Objects between Node and Redis (YouTube)

Redis University

Redis for JavaScript Developers

Build full-fledged Redis applications with Node.js and Express.