Skip to content

Commit 3f5c25a

Browse files
committed
Redis caching feature started
1 parent 02627a1 commit 3f5c25a

File tree

8 files changed

+191
-11
lines changed

8 files changed

+191
-11
lines changed

.env.development

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ ERROR_FORBIDDEN_CODE=403
1414

1515
# JWT secret
1616
JWT_SECRET="superSKR"
17-
JWT_TOKEN_EXPIRES_IN="10m"
17+
JWT_TOKEN_EXPIRES_IN="10m"
18+
19+
# REDIS related
20+
REDIS_CONNECTION_URL="redis://35.154.200.227:6379"

package-lock.json

Lines changed: 149 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"dependencies": {
1717
"jsonwebtoken": "^8.5.1",
18-
"mongodb": "^4.7.0"
18+
"mongodb": "^4.7.0",
19+
"redis": "^4.1.1"
1920
}
2021
}
File renamed without changes.

src/helpers/redisHelpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const connectRedis = async () => {
2+
await client.connect();
3+
};
4+
5+
export { connectRedis };

src/lib/redisClient.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createClient } from "redis";
2+
3+
const redisClient = createClient({
4+
url: process.env.REDIS_CONNECTION_URL,
5+
});
6+
7+
export { redisClient };
8+
// on all error execute this line
9+
// client.on("error", (err) => console.log("Redis Error: ", err.toString()));
10+
11+
// await client.connect();
12+
// await client.set("num", 23);
13+
// const value = await client.get("num");
14+
// console.log("Value as received", value);
15+
16+
// const nameVal = await client.get("name");
17+
// console.log("Name vlaue: ", nameVal);
18+
19+
// // const an object as key
20+
// const keyObj = { username: "anij123" };
21+
// const keyObjVal = { name: "Anijit Sau", role: "Developer", country: "India" };
22+
// await client.hSet("anij123", keyObjVal);
23+
// const valueKeyObj = await client.hGetAll("anij123");
24+
// console.log(
25+
// "value received :",
26+
// valueKeyObj,
27+
// " \nand its type: ",
28+
// typeof valueKeyObj
29+
// );

src/services/loginService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// local dependencies
2-
import { createToken } from "../helpers/jwtHelper.js";
2+
import { createToken } from "../helpers/jwtHelpers.js";
33
import { sendResponse } from "../helpers/sendResponse.js";
44
import { findUserFromDb } from "../dbRelated/logindDbOps.js";
55

src/services/userService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
sendForbiddenResponse,
1212
} from "../helpers/sendResponse.js";
1313

14-
import { verifyToken } from "../helpers/jwtHelper.js";
14+
import { verifyToken } from "../helpers/jwtHelpers.js";
1515

1616
const getAllUsersHandler = async (event) => {
1717
const verified = verifyToken(event);

0 commit comments

Comments
 (0)