Skip to content

feat: add keepAlive parameter #1138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024
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
5 changes: 4 additions & 1 deletion pkg/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type HttpClientConfig = {
retry?: RetryConfig;
agent?: any;
signal?: AbortSignal;
keepAlive?: boolean
} & RequesterConfig;

export class HttpClient implements Requester {
Expand All @@ -105,6 +106,7 @@ export class HttpClient implements Requester {
signal?: AbortSignal;
responseEncoding?: false | "base64";
cache?: CacheSetting;
keepAlive: boolean
};

public readonly retry: {
Expand All @@ -119,6 +121,7 @@ export class HttpClient implements Requester {
responseEncoding: config.responseEncoding ?? "base64", // default to base64
cache: config.cache,
signal: config.signal,
keepAlive: config.keepAlive ?? true
};

this.baseUrl = config.baseUrl.replace(/\/$/, "");
Expand Down Expand Up @@ -175,7 +178,7 @@ export class HttpClient implements Requester {
method: "POST",
headers: this.headers,
body: JSON.stringify(req.body),
keepalive: true,
keepalive: this.options.keepAlive,
agent: this.options?.agent,
signal: this.options.signal,

Expand Down
4 changes: 3 additions & 1 deletion platforms/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type RedisConfigCloudflare = {
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
*/
signal?: AbortSignal;
keepAlive?: boolean;
} & core.RedisOptions &
RequesterConfig &
Env;
Expand Down Expand Up @@ -69,13 +70,14 @@ export class Redis extends core.Redis {
headers: { authorization: `Bearer ${config.token}` },
responseEncoding: config.responseEncoding,
signal: config.signal,
keepAlive: config.keepAlive,
});

super(client, {
enableTelemetry: !env?.UPSTASH_DISABLE_TELEMETRY,
automaticDeserialization: config.automaticDeserialization,
latencyLogging: config.latencyLogging,
enableAutoPipelining: config.enableAutoPipelining
enableAutoPipelining: config.enableAutoPipelining,
});
// This is only added of the user has not disabled telemetry
this.addTelemetry({
Expand Down
2 changes: 2 additions & 0 deletions platforms/fastly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type RedisConfigFastly = {
* referenced by name.
*/
backend: string;
keepAlive?: boolean;
} & core.RedisOptions &
RequesterConfig;

Expand Down Expand Up @@ -67,6 +68,7 @@ export class Redis extends core.Redis {
headers: { authorization: `Bearer ${config.token}` },
options: { backend: config.backend },
responseEncoding: config.responseEncoding,
keepAlive: config.keepAlive,
});

super(client, {
Expand Down
2 changes: 2 additions & 0 deletions platforms/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type RedisConfigNodejs = {
signal?: AbortSignal;
latencyLogging?: boolean;
agent?: any;
keepAlive?: boolean;
} & core.RedisOptions &
RequesterConfig;

Expand Down Expand Up @@ -131,6 +132,7 @@ export class Redis extends core.Redis {
responseEncoding: configOrRequester.responseEncoding,
cache: configOrRequester.cache || "no-store",
signal: configOrRequester.signal,
keepAlive: configOrRequester.keepAlive,
});

super(client, {
Expand Down
Loading