Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,16 @@ jobs:

- name: Deploy
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
pnpm --dir=examples/nextjs add @upstash/redis@${{needs.release.outputs.version}}
DEPLOYMENT_URL=$(npx vercel --token=${{ secrets.VERCEL_TOKEN }})
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> $GITHUB_ENV
env:
VERCEL_ORG_ID: ${{secrets.VERCEL_TEAM_ID}}
VERCEL_PROJECT_ID: "prj_pFFK1XgNIlnW014iiuqAIQmBBuZA"

- name: Test
run: deno test --allow-net --allow-env ./examples/nextjs/test.ts
run: deno test --allow-net --allow-env ./test.ts
working-directory: examples/nextjs

nextjs-export-deployed:
concurrency: nextjs-export-deployed
Expand All @@ -395,7 +396,7 @@ jobs:

- name: Deploy
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
pnpm --dir=examples/nextjs add @upstash/redis@${{needs.release.outputs.version}}
DEPLOYMENT_URL=$(npx vercel --token=${{ secrets.VERCEL_TOKEN }})
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> $GITHUB_ENV
env:
Expand Down Expand Up @@ -428,7 +429,7 @@ jobs:

- name: Deploy
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
pnpm --dir=examples/nextjs add @upstash/redis@${{needs.release.outputs.version}}
DEPLOYMENT_URL=$(npx vercel --token=${{ secrets.VERCEL_TOKEN }})
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> $GITHUB_ENV
env:
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "next start"
},
"dependencies": {
"@upstash/redis": "^1.15.0",
"@upstash/redis": "0.0.0-ci.1882836b-20221026",
"next": "^12.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
30 changes: 15 additions & 15 deletions examples/nextjs/pages/api/hello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { NextApiRequest, NextApiResponse } from "next";
const redis = Redis.fromEnv({ automaticDeserialization: true });

export default async function handler(
_req: NextApiRequest,
res: NextApiResponse,
_req: NextApiRequest,
res: NextApiResponse,
) {
/**
* We're prefixing the key for our automated tests.
* This is to avoid collisions with other tests.
*/
const key = [
"vercel",
process.env.VERCEL_GIT_COMMIT_SHA || "local",
"nextjs",
"random",
].join("_");
await redis.set(key, `${Math.floor(Math.random() * 100)}_hello 😋`);
const value = await redis.get(key);
res.json({ key, value });
/**
* We're prefixing the key for our automated tests.
* This is to avoid collisions with other tests.
*/
const key = [
"vercel",
process.env.VERCEL_GIT_COMMIT_SHA || "local",
"nextjs",
"random",
].join("_");
await redis.set(key, `${Math.floor(Math.random() * 100)}_hello 😋`);
const value = await redis.get(key);
res.json({ key, value });
}
5 changes: 3 additions & 2 deletions examples/nextjs/pages/api/incr.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Redis } from "@upstash/redis";
import type { NextApiRequest, NextApiResponse } from "next";

import https from "https";
const agent = new https.Agent({ keepAlive: true });
export default async function handler(
_req: NextApiRequest,
res: NextApiResponse,
) {
const redis = Redis.fromEnv();
const redis = Redis.fromEnv({ agent });

/**
* We're prefixing the key for our automated tests.
Expand Down
8 changes: 5 additions & 3 deletions pkg/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export type HttpClientConfig = {
baseUrl: string;
options?: Options;
retry?: RetryConfig;
agent?: any;
};

export class HttpClient implements Requester {
public baseUrl: string;
public headers: Record<string, string>;
public readonly options?: { backend?: string };
public readonly options?: { backend?: string; agent: any };

public readonly retry: {
attempts: number;
Expand All @@ -67,7 +68,7 @@ export class HttpClient implements Requester {
...config.headers,
};

this.options = { backend: config.options?.backend };
this.options = { backend: config.options?.backend, agent: config.agent };

if (typeof config?.retry === "boolean" && config?.retry === false) {
this.retry = {
Expand All @@ -86,11 +87,12 @@ export class HttpClient implements Requester {
public async request<TResult>(
req: UpstashRequest,
): Promise<UpstashResponse<TResult>> {
const requestOptions: RequestInit & { backend?: string } = {
const requestOptions: RequestInit & { backend?: string; agent?: any } = {
method: "POST",
headers: this.headers,
body: JSON.stringify(req.body),
keepalive: true,
agent: this.options?.agent,

/**
* Fastly specific
Expand Down
9 changes: 3 additions & 6 deletions platforms/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
UpstashRequest,
UpstashResponse,
} from "../pkg/http.ts";
// @ts-ignore Deno can't compile
// import https from "https";
// @ts-ignore Deno can't compile
// import http from "http";
// import "isomorphic-fetch";

export type { Requester, UpstashRequest, UpstashResponse };
Expand All @@ -29,6 +25,7 @@ export type RedisConfigNodejs = {
* UPSTASH_REDIS_REST_TOKEN
*/
token: string;

/**
* An agent allows you to reuse connections to reduce latency for multiple sequential requests.
*
Expand All @@ -44,7 +41,7 @@ export type RedisConfigNodejs = {
* }
* ```
*/
// agent?: http.Agent | https.Agent;
agent?: any;

/**
* Configure the retry behaviour in case of network errors
Expand Down Expand Up @@ -115,7 +112,7 @@ export class Redis extends core.Redis {
baseUrl: configOrRequester.url,
retry: configOrRequester.retry,
headers: { authorization: `Bearer ${configOrRequester.token}` },
// agent: configOrRequester.agent,
agent: configOrRequester.agent,
});

super(client, {
Expand Down