Skip to content

Commit

Permalink
feat: add keepAlive parameter (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda authored Jun 20, 2024
1 parent 4a141b4 commit 6b895d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
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

0 comments on commit 6b895d1

Please sign in to comment.