Skip to content

Commit 6b895d1

Browse files
authored
feat: add keepAlive parameter (#1138)
1 parent 4a141b4 commit 6b895d1

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

pkg/http.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export type HttpClientConfig = {
9494
retry?: RetryConfig;
9595
agent?: any;
9696
signal?: AbortSignal;
97+
keepAlive?: boolean
9798
} & RequesterConfig;
9899

99100
export class HttpClient implements Requester {
@@ -105,6 +106,7 @@ export class HttpClient implements Requester {
105106
signal?: AbortSignal;
106107
responseEncoding?: false | "base64";
107108
cache?: CacheSetting;
109+
keepAlive: boolean
108110
};
109111

110112
public readonly retry: {
@@ -119,6 +121,7 @@ export class HttpClient implements Requester {
119121
responseEncoding: config.responseEncoding ?? "base64", // default to base64
120122
cache: config.cache,
121123
signal: config.signal,
124+
keepAlive: config.keepAlive ?? true
122125
};
123126

124127
this.baseUrl = config.baseUrl.replace(/\/$/, "");
@@ -175,7 +178,7 @@ export class HttpClient implements Requester {
175178
method: "POST",
176179
headers: this.headers,
177180
body: JSON.stringify(req.body),
178-
keepalive: true,
181+
keepalive: this.options.keepAlive,
179182
agent: this.options?.agent,
180183
signal: this.options.signal,
181184

platforms/cloudflare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type RedisConfigCloudflare = {
2828
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
2929
*/
3030
signal?: AbortSignal;
31+
keepAlive?: boolean;
3132
} & core.RedisOptions &
3233
RequesterConfig &
3334
Env;
@@ -69,13 +70,14 @@ export class Redis extends core.Redis {
6970
headers: { authorization: `Bearer ${config.token}` },
7071
responseEncoding: config.responseEncoding,
7172
signal: config.signal,
73+
keepAlive: config.keepAlive,
7274
});
7375

7476
super(client, {
7577
enableTelemetry: !env?.UPSTASH_DISABLE_TELEMETRY,
7678
automaticDeserialization: config.automaticDeserialization,
7779
latencyLogging: config.latencyLogging,
78-
enableAutoPipelining: config.enableAutoPipelining
80+
enableAutoPipelining: config.enableAutoPipelining,
7981
});
8082
// This is only added of the user has not disabled telemetry
8183
this.addTelemetry({

platforms/fastly.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type RedisConfigFastly = {
2626
* referenced by name.
2727
*/
2828
backend: string;
29+
keepAlive?: boolean;
2930
} & core.RedisOptions &
3031
RequesterConfig;
3132

@@ -67,6 +68,7 @@ export class Redis extends core.Redis {
6768
headers: { authorization: `Bearer ${config.token}` },
6869
options: { backend: config.backend },
6970
responseEncoding: config.responseEncoding,
71+
keepAlive: config.keepAlive,
7072
});
7173

7274
super(client, {

platforms/nodejs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type RedisConfigNodejs = {
5656
signal?: AbortSignal;
5757
latencyLogging?: boolean;
5858
agent?: any;
59+
keepAlive?: boolean;
5960
} & core.RedisOptions &
6061
RequesterConfig;
6162

@@ -131,6 +132,7 @@ export class Redis extends core.Redis {
131132
responseEncoding: configOrRequester.responseEncoding,
132133
cache: configOrRequester.cache || "no-store",
133134
signal: configOrRequester.signal,
135+
keepAlive: configOrRequester.keepAlive,
134136
});
135137

136138
super(client, {

0 commit comments

Comments
 (0)