-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redis connection pool implementation
- Loading branch information
Showing
15 changed files
with
261 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Set the maximum allowed number of connected clients. | ||
# However, ensure your system has adequate resources to handle this. | ||
maxclients 10000 | ||
|
||
# Set a timeout to close idle connections after a period (in seconds). | ||
timeout 60 | ||
|
||
# Enable append only mode for better data durability. | ||
appendonly yes | ||
|
||
# Set the frequency at which Redis fsyncs the AOF. | ||
appendfsync everysec | ||
|
||
# Slow log logging level (0 = don't log, 1 = log the slower queries, 2 = log all) | ||
slowlog-log-slower-than 10000 | ||
|
||
# Maximum length of the slow query log | ||
slowlog-max-len 128 |
Empty file.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { RedisManager } from "@providers/database/RedisManager/RedisManager"; | ||
import { provide } from "inversify-binding-decorators"; | ||
import { CronJobScheduler } from "./CronJobScheduler"; | ||
|
||
@provide(RedisCrons) | ||
export class RedisCrons { | ||
constructor(private cronJobScheduler: CronJobScheduler, private redisManager: RedisManager) {} | ||
|
||
public schedule(): void { | ||
// every 5 minutes | ||
this.cronJobScheduler.uniqueSchedule("redis-client-connection-count", "* * * * *", async () => { | ||
await this.redisManager.getClientCount(); | ||
}); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable no-async-promise-executor */ | ||
import { appEnv } from "@providers/config/env"; | ||
import { provideSingleton } from "@providers/inversify/provideSingleton"; | ||
import mongoose from "mongoose"; | ||
import { createClient } from "redis"; | ||
import { applySpeedGooseCacheLayer } from "speedgoose"; | ||
|
||
//! in unit test, just use the traditional redis because its already being mocked by redisV4Mock and changing support to IORedis would be a pain | ||
|
||
@provideSingleton(RedisBareClient) | ||
export class RedisBareClient { | ||
public async connect(): Promise<void> { | ||
return await new Promise<void>(async (resolve, reject) => { | ||
let client; | ||
|
||
try { | ||
const redisConnectionUrl = `redis://${appEnv.database.REDIS_CONTAINER}:${appEnv.database.REDIS_PORT}`; | ||
|
||
client = createClient({ | ||
url: redisConnectionUrl, | ||
}); | ||
|
||
client.on("error", (err) => { | ||
console.log("❌ Redis error:", err); | ||
reject(err); | ||
}); | ||
|
||
await client.connect(); | ||
|
||
// @ts-ignore | ||
void applySpeedGooseCacheLayer(mongoose, { | ||
redisUri: redisConnectionUrl, | ||
}); | ||
|
||
resolve(client); | ||
} catch (error) { | ||
console.log("❌ Redis initialization error: ", error); | ||
reject(error); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.