Skip to content

Redis middleware

Install dependencies

cmd
bun add @redis/client

Copy paste the following code in your lib/redis.ts file.

src/lib/redis.ts
import { createClient } from "@redis/client";
 
export const getRedisClient = async () => {
  const client = createClient({
    url: process.env.REDIS_CONNECTION_STRING,
  });
 
  client.on("error", (err) => {
    console.error("Redis client error:", err);
  });
 
  await client.connect();
  return client;
};