Skip to content

Commit 0ff555c

Browse files
committed
add redis implementation
1 parent a8be3a5 commit 0ff555c

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

Diff for: bin/www

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const logger = require("../dist/config/loggerConfig").default;
1010
var http = require("http");
1111

1212
const { PORT } = require("../dist/config/index");
13+
const { connectToRedis } = require("../dist/db/redis.js");
1314

1415
app.set("port", PORT);
1516

@@ -21,5 +22,6 @@ var server = http.createServer(app);
2122

2223
server.listen(PORT, async () => {
2324
await seedDatabase();
25+
await connectToRedis();
2426
logger.debug(`Server running on port ${PORT}`);
2527
});

Diff for: package-lock.json

+83
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"passport-google-oauth2": "^0.2.0",
3434
"passport-local": "^1.0.0",
3535
"pg": "^8.11.3",
36+
"redis": "^4.6.13",
3637
"response-time": "^2.3.2",
3738
"winston": "^3.11.0"
3839
},

Diff for: src/db/redis.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createClient } from "redis";
2+
3+
const redisClient = createClient({
4+
url: process.env.REDIS_URL as string,
5+
});
6+
7+
export async function connectToRedis() {
8+
await redisClient.connect();
9+
10+
redisClient.on("error", (error) => {
11+
console.error(`Error connecting to Redis: ${error}`);
12+
});
13+
14+
return redisClient;
15+
}
16+
17+
export default redisClient;

0 commit comments

Comments
 (0)