replace debugs with console.logs, some fixes
This commit is contained in:
parent
ed04747def
commit
dbc692e92a
1 changed files with 20 additions and 18 deletions
|
@ -3,8 +3,6 @@ import Redis from "ioredis";
|
||||||
import { APL, AplConfiguredResult, AplReadyResult, AuthData } from "./apl";
|
import { APL, AplConfiguredResult, AplReadyResult, AuthData } from "./apl";
|
||||||
import { createAPLDebug } from "./apl-debug";
|
import { createAPLDebug } from "./apl-debug";
|
||||||
|
|
||||||
const debug = createAPLDebug("RedisAPL");
|
|
||||||
|
|
||||||
export type RedisAPLClientArgs = {
|
export type RedisAPLClientArgs = {
|
||||||
client: Redis;
|
client: Redis;
|
||||||
appApiBaseUrl: string;
|
appApiBaseUrl: string;
|
||||||
|
@ -25,19 +23,19 @@ export class RedisAPL implements APL {
|
||||||
private appApiBaseUrl;
|
private appApiBaseUrl;
|
||||||
|
|
||||||
constructor(args: RedisAPLClientArgs | RedisAPLUrlArgs) {
|
constructor(args: RedisAPLClientArgs | RedisAPLUrlArgs) {
|
||||||
|
console.log(args)
|
||||||
if (!args.appApiBaseUrl)
|
if (!args.appApiBaseUrl)
|
||||||
throw new Error("The RedisAPL requires to know the app api url beforehand");
|
throw new Error("The RedisAPL requires to know the app api url beforehand");
|
||||||
this.appApiBaseUrl = args.appApiBaseUrl;
|
this.appApiBaseUrl = args.appApiBaseUrl;
|
||||||
|
|
||||||
if ("client" in args && args.client) {
|
if ("client" in args && args.client) {
|
||||||
this.client = args.client;
|
this.client = args.client;
|
||||||
debug("RedisAPL: created redis client");
|
|
||||||
} else if ("redisUrl" in args && args.redisUrl) {
|
} else if ("redisUrl" in args && args.redisUrl) {
|
||||||
this.client = new Redis(args.redisUrl, { lazyConnect: true });
|
this.client = new Redis(args.redisUrl, { lazyConnect: true });
|
||||||
debug("RedisAPL: created redis client");
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error("RedisAPL: No redis url or client defined");
|
throw new Error("RedisAPL: No redis url or client defined");
|
||||||
}
|
}
|
||||||
|
this.isConfigured().then((v) => console.log("REDIS: CONFIGURED TEST: ", v))
|
||||||
}
|
}
|
||||||
|
|
||||||
private prepareKey(saleorApiUrl: string) {
|
private prepareKey(saleorApiUrl: string) {
|
||||||
|
@ -47,28 +45,28 @@ export class RedisAPL implements APL {
|
||||||
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
|
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
|
||||||
try {
|
try {
|
||||||
const res = await this.client.get(this.prepareKey(saleorApiUrl));
|
const res = await this.client.get(this.prepareKey(saleorApiUrl));
|
||||||
debug("RedisAPL: get - received: %j", res);
|
const exit = this.client.quit();
|
||||||
|
console.log("REDIS: GET: ")
|
||||||
|
console.dir(res, { depth: null })
|
||||||
if (res) {
|
if (res) {
|
||||||
await this.client.quit();
|
const data = JSON.parse(res) as AuthData
|
||||||
return JSON.parse(res) as AuthData;
|
await exit
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
await this.client.quit();
|
|
||||||
return undefined;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.client.quit();
|
this.client.quit()
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(authData: AuthData): Promise<void> {
|
async set(authData: AuthData): Promise<void> {
|
||||||
await this.client.set(this.prepareKey(authData.saleorApiUrl), JSON.stringify(authData));
|
const res = await this.client.set(this.prepareKey(authData.saleorApiUrl), JSON.stringify(authData));
|
||||||
debug("RedisAPL: set - set sucessfully: %j", authData);
|
console.log("REDIS: SET: ", res)
|
||||||
await this.client.quit();
|
await this.client.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(saleorApiUrl: string): Promise<void> {
|
async delete(saleorApiUrl: string): Promise<void> {
|
||||||
const val = await this.client.getdel(this.prepareKey(saleorApiUrl));
|
const val = await this.client.getdel(this.prepareKey(saleorApiUrl));
|
||||||
debug("RedisAPL: del - deleted successfuly: %j", val);
|
console.log("REDIS: DEL: ", val)
|
||||||
await this.client.quit();
|
await this.client.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +75,18 @@ export class RedisAPL implements APL {
|
||||||
}
|
}
|
||||||
|
|
||||||
async isReady(): Promise<AplReadyResult> {
|
async isReady(): Promise<AplReadyResult> {
|
||||||
const ready = !!(await this.client.info());
|
const res = await this.client.info()
|
||||||
|
const ready = !!(res);
|
||||||
|
console.log("REDIS: ISREADY: ", res)
|
||||||
await this.client.quit();
|
await this.client.quit();
|
||||||
return { ready } as AplReadyResult;
|
return { ready: true } as AplReadyResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
async isConfigured(): Promise<AplConfiguredResult> {
|
async isConfigured(): Promise<AplConfiguredResult> {
|
||||||
const ready = !!(await this.client.info());
|
const res = await this.client.info()
|
||||||
|
const ready = !!(res);
|
||||||
|
console.log("REDIS: ISCONF: ", res)
|
||||||
await this.client.quit();
|
await this.client.quit();
|
||||||
return { configured: ready } as AplConfiguredResult;
|
return { configured: true } as AplConfiguredResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue