Node.js and Redis

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

Getting Started#

The Node.js community has built many client libraries that you can find here. For your first steps with Node.js and Redis, this article will show how to use the recommended libraries: ioredis and node-redis.

Step 1. Install the ioredis library using npm (or yarn)#

npm install ioredis

Step 2. Write your application code#

const Redis = require("ioredis");
const redis = new Redis(6379, "localhost");
redis.set("mykey", "Hello from io-redis!");
redis.get("mykey", function(err, result){
if (err) { throw err; }
// use the promise instead of callback
redis.get("mykey").then(function (result) {
redis.zadd("vehicles", 0, "car", 0, "bike");
redis.zrange("vehicles", 0, -1, "WITHSCORES").then((res) => console.log(res));

Find more information about Redis & io-redis connections in the "Redis Connect".

More developer resources#

Sample Code#

Basic Redis Caching This application call the GitHub API and cache 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 allow 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.