-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) add validation error message based on type
- Loading branch information
1 parent
e031b34
commit 0d099bd
Showing
7 changed files
with
61 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { RedisClient } from "utils/redis"; | ||
import { RedisClient } from "utils/redis" | ||
|
||
async function addToRedis(key, data: Object) { | ||
const redisClient = RedisClient.getInstance(); | ||
await redisClient.set(key, JSON.stringify(data)); | ||
const redisClient = RedisClient.getInstance() | ||
await redisClient.set(key, JSON.stringify(data)) | ||
} | ||
function addToRedisFromPromise(key, data: Promise<Object>) { | ||
const redisClient = RedisClient.getInstance(); | ||
const redisClient = RedisClient.getInstance() | ||
data | ||
.then((resp) => redisClient.set(key, JSON.stringify(resp))) | ||
.catch((err) => redisClient.set(key, JSON.stringify(err))); | ||
.then(resp => redisClient.set(key, JSON.stringify(resp))) | ||
.catch(err => redisClient.set(key, JSON.stringify(err))) | ||
} | ||
|
||
async function getFromRedis(key) { | ||
const redisClient = RedisClient.getInstance(); | ||
return JSON.parse(await redisClient.get(key)); | ||
const redisClient = RedisClient.getInstance() | ||
return JSON.parse(await redisClient.get(key)) | ||
} | ||
|
||
async function deleteKeyFromRedis(key) { | ||
const redisClient = RedisClient.getInstance(); | ||
return await redisClient.del([key]); | ||
const redisClient = RedisClient.getInstance() | ||
return await redisClient.del([key]) | ||
} | ||
|
||
export { addToRedis, addToRedisFromPromise, getFromRedis, deleteKeyFromRedis }; | ||
export { addToRedis, addToRedisFromPromise, getFromRedis, deleteKeyFromRedis } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import IORedis from "ioredis"; | ||
import IORedis from "ioredis" | ||
|
||
export class RedisClient { | ||
private static instance: RedisClient; | ||
private static client: IORedis; | ||
private static instance: RedisClient | ||
private static client: IORedis | ||
|
||
private constructor(url) { | ||
RedisClient.client = new IORedis(url); | ||
RedisClient.client = new IORedis(url) | ||
} | ||
|
||
public static getInstance(): IORedis { | ||
if (!RedisClient.instance) { | ||
RedisClient.instance = new RedisClient(process.env.REDIS_URL); | ||
RedisClient.instance = new RedisClient(process.env.REDIS_URL) | ||
} | ||
|
||
return RedisClient.client; | ||
return RedisClient.client | ||
} | ||
} |