change appId for appApiBaseUrl for redis key
This commit is contained in:
parent
30ff2b0712
commit
1df136daa6
2 changed files with 8 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
export * from "./apl";
|
export * from "./apl";
|
||||||
export * from "./env-apl";
|
export * from "./env-apl";
|
||||||
export * from "./file-apl";
|
export * from "./file-apl";
|
||||||
|
export * from "./redis-apl";
|
||||||
export * from "./saleor-cloud-apl";
|
export * from "./saleor-cloud-apl";
|
||||||
export * from "./upstash-apl";
|
export * from "./upstash-apl";
|
||||||
export * from "./redis-apl"
|
|
||||||
|
|
|
@ -14,18 +14,18 @@ const debug = createAPLDebug("UpstashAPL");
|
||||||
export class RedisAPL implements APL {
|
export class RedisAPL implements APL {
|
||||||
private client;
|
private client;
|
||||||
|
|
||||||
private appID;
|
private appApiBaseUrl;
|
||||||
|
|
||||||
constructor(redisURL: URL, appID: string) {
|
constructor(redisURL: URL, appApiBaseUrl: string) {
|
||||||
if (!redisURL) throw new Error("No redis url defined");
|
if (!redisURL) throw new Error("No redis url defined");
|
||||||
if (!appID) throw new Error("The RedisAPL requires to know the app ID beforehand");
|
if (!appApiBaseUrl) throw new Error("The RedisAPL requires to know the app ID beforehand");
|
||||||
this.appID = appID;
|
this.appApiBaseUrl = appApiBaseUrl;
|
||||||
this.client = createClient({ url: redisURL.toString() });
|
this.client = createClient({ url: redisURL.toString() });
|
||||||
debug("RedisAPL: createClient.url : %j", redisURL.toString());
|
debug("RedisAPL: createClient.url : %j", redisURL.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private prepareKey(saleorApiUrl: string) {
|
private prepareKey(saleorApiUrl: string) {
|
||||||
return `${this.appID}:${saleorApiUrl}`;
|
return `${this.appApiBaseUrl}:${saleorApiUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
|
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
|
||||||
|
@ -34,16 +34,15 @@ export class RedisAPL implements APL {
|
||||||
const res = await this.client.get(this.prepareKey(saleorApiUrl));
|
const res = await this.client.get(this.prepareKey(saleorApiUrl));
|
||||||
debug("RedisAPL: get - received: %j", res);
|
debug("RedisAPL: get - received: %j", res);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
await this.client.disconnect();
|
||||||
return JSON.parse(res) as AuthData;
|
return JSON.parse(res) as AuthData;
|
||||||
}
|
}
|
||||||
|
await this.client.disconnect();
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.client.disconnect();
|
await this.client.disconnect();
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(authData: AuthData): Promise<void> {
|
async set(authData: AuthData): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue