Skip to content

Commit

Permalink
fix: redis connection-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya062003 committed Apr 11, 2024
1 parent f4c671b commit f6bace4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion controllers/customerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ require("dotenv").config();

const Redis = require("ioredis");
const redisUri = process.env.REDIS_URI;
const redis = new Redis(redisUri);
const redis = new Redis(redisUri, {
enableOfflineQueue: false,
legacyMode: true,
});

//@desc Get All Vendors
//@route GET /api/customer/Vendors
Expand Down Expand Up @@ -61,6 +64,9 @@ exports.getVendors = asyncHandler(async (req, res) => {
return res.status(200).json(vendors);
} catch (err) {
return res.status(500).json({ error: "Internal Server Error" });
} finally {
// Disconnect from Redis after operation
redis.disconnect();
}
});

Expand Down Expand Up @@ -217,6 +223,9 @@ exports.getCartPrice = asyncHandler(async (req, res) => {
return res.json({ totalPrice });
} catch (error) {
return res.status(500).json({ error: error.message });
} finally {
// Disconnect from Redis after operation
redis.disconnect();
}
});

Expand Down Expand Up @@ -277,6 +286,9 @@ exports.searchRestaurants = asyncHandler(async (req, res) => {
return res.status(200).json(restaurants);
} catch (error) {
return res.status(500).json({ error: "Internal Server Error" });
} finally {
// Disconnect from Redis after operation
redis.disconnect();
}
});

Expand Down Expand Up @@ -307,6 +319,9 @@ exports.searchMenuItems = asyncHandler(async (req, res) => {
return res.status(200).json(menuItems);
} catch (error) {
return res.status(500).json({ error: "Internal Server Error" });
} finally {
// Disconnect from Redis after operation
redis.disconnect();
}
});
exports.getOfferItems = asyncHandler(async (req, res) => {
Expand Down

0 comments on commit f6bace4

Please sign in to comment.