Lesson 18 / 20
Redis in a Node App
Connect to Redis from Node.js with the official redis package and cache values using async commands.
Install the client
The official redis package works well for most Node apps.
npm install redisConnect & use it
The client mirrors Redis commands as async methods, so caching a value looks almost like the CLI.
import { createClient } from 'redis';
const client = createClient({ url: 'redis://localhost:6379' });
await client.connect();
await client.set('greeting', 'hello', { EX: 60 });
const value = await client.get('greeting');
console.log(value); // 'hello'