Skip to content

Talking to redis via Node.js

Course: Redis (Pub subs and Messaging queues) - chapter 6

There are various clients that exist that let you talk to redis via Node.js

https://www.npmjs.com/package/redis

Let’s initialize a simple Node.js express server that takes a problem submission (very similar to leetcode) as input and sends it to the queue

Let’s also create a worker service that picks up a problem, waits for 2 seconds and then proceeds to pick the next one

  • Create an empty Node.js project
  • Initialize 2 folders inside it
    • express-server
    • worker
  • Initialize an empty Node.js typescript project in both of them
npm init -y
npx tsc --init
  • Install dependencies in express-server
npm i express @types/express redis
  • Install dependencies in worker
npm i redis
  • Create index.ts in express-server
$1b
  • Create index.ts in worker
$1d

💡 Can u figure out why I had to add a ts-ignore ? Why is the type of submission string?