diff --git a/examples/vercel-functions-app-router/app/api/custom-requester/route.ts b/examples/vercel-functions-app-router/app/api/custom-requester/route.ts new file mode 100644 index 00000000..74455468 --- /dev/null +++ b/examples/vercel-functions-app-router/app/api/custom-requester/route.ts @@ -0,0 +1,25 @@ +import { Redis, Requester, UpstashResponse } from "@upstash/redis"; + +/** + * it's possible to create a Redis client with a custom requester + * implementation. This can be useful if you want to modify the + * request/response behavior, add custom logging, or integrate with + * other libraries. + * + * In this example, we create a simple custom requester that logs + * the request options and returns a mock response. + */ + +const requester = { + request: async (opts) => { + console.log("Custom requester called with:", opts); + return { result: "custom response" } as UpstashResponse; + }, +} satisfies Requester + +const redis = new Redis(requester) + +export async function GET() { + const response = await redis.get("mykey"); + return new Response(JSON.stringify({ response })); +} \ No newline at end of file diff --git a/platforms/nodejs.ts b/platforms/nodejs.ts index 95d9dc41..201c0db5 100644 --- a/platforms/nodejs.ts +++ b/platforms/nodejs.ts @@ -78,6 +78,11 @@ export class Redis extends core.Redis { */ constructor(config: RedisConfigNodejs); + /** + * Create a new redis client by providing a custom `Requester` implementation + */ + constructor(requester: Requester); + /** * Create a new redis client by providing a custom `Requester` implementation *