@@ -7,18 +7,31 @@ import {
77 convertToObjectId ,
88} from "../helpers/dbHelpers.js" ;
99
10- // top level await to connect the MongoDB Atlas
11- // const client = await dbClient.connect();
10+ // redis dependencies
11+ import {
12+ setValueToRedis ,
13+ getValueFromRedis ,
14+ connectRedis ,
15+ closeConnectionToRedis ,
16+ } from "../helpers/redisHelpers.js" ;
1217
1318// all the db related process variables
14- const {
15- DB_NAME ,
16- COLLECTION_USER_STICKER ,
17- SUCCESS_CODE ,
18- ERROR_CODE ,
19- } = process . env ;
19+ const { DB_NAME , COLLECTION_USER_STICKER , SUCCESS_CODE , ERROR_CODE } =
20+ process . env ;
2021
2122const getAllUsers = async ( ) => {
23+ // redis operations
24+ let usersInCache = [ ] ;
25+ try {
26+ await connectRedis ( ) ;
27+ usersInCache = await getValueFromRedis ( "allUsers" ) ;
28+ await closeConnectionToRedis ( ) ;
29+ } catch ( error ) {
30+ return sendResponse ( ERROR_CODE , {
31+ message : "Unable to get records from Redis" ,
32+ error : error . toString ( ) ,
33+ } ) ;
34+ }
2235 const client = await createConnectionToDB ( ) ;
2336 try {
2437 // select the db, Collections are selected based on needs
@@ -31,7 +44,7 @@ const getAllUsers = async () => {
3144 . toArray ( ) ;
3245
3346 const users = data . length > 0 ? [ ...data ] : [ ] ;
34- const res = { users } ;
47+ const res = { users, usersInCache } ;
3548
3649 return sendResponse ( SUCCESS_CODE , res ) ;
3750 } catch ( error ) {
0 commit comments