Node.js and Redis

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

Getting Started#

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

Redis Node.js has two primary clients available node_redis and ioredis. Both are available through npm. Both clients have pros and cons, but we generally suggest node_redis, as it has wide support for Redis modules, it is easily extensible and widely used. Ioredis has better integrated support for the Redis Enterprise Cluster API, but this is only relevant if you're specifically using the Cluster API topology instead of the more common Proxy topology. Node_redis’ support for the Cluster API is provided by an additional shim, redis-clustr. Node_redis has built-in support for Redis Enterprise features such as Active Active geo distribution, allowing you to have one database that spans multiple clusters. Node_redis also supports Redis-on-Flash which enables extending your database into Flash SSD storage for warm values and DRAM for hot values. Nodejs redis enables you to integrate such features.

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".

Redis Marketplace#

Redis Marketplace is like an “App Store” for Redis sample apps. You can easily find apps for your preferred frameworks and languages. Below are few of these apps. Click here to access the complete lists of apps

Hacker News Clone in NodeJS#


A Hacker News Clone project built in NextJS, NodeJS and Express based on RediSearch & RedisJSON

Shopping Cart app in NodeJS#


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.