How to use Redis with Node.js (ioredis)

Redis and Node.js
Redis and Node.js

Install

Install ioredis:

npm install ioredis

Connect

Import Redis:

redis://<REDIS_USER>:<REDIS_PASSWORD>@<REDIS_HOST>:<REDIS_PORT>
redis://localhost:6379

Commands

set

Set key with value:

get

Get value from key:

del

Delete key-value pair:

keys

Search by key:

scan

Scan performs better than keys if there’s a lot of data:

Demo

Replit:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store