From 30ee9b2aa48e49905b713ee226268cd5c9c98662 Mon Sep 17 00:00:00 2001 From: Mithun James <1007084+drtechie@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:35:39 +0530 Subject: [PATCH] fix: save minimal data to users_ key of Redis --- .../iemr/inventory/utils/JwtAuthenticationUtil.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/inventory/utils/JwtAuthenticationUtil.java b/src/main/java/com/iemr/inventory/utils/JwtAuthenticationUtil.java index 3f331a55..4f3f29f5 100644 --- a/src/main/java/com/iemr/inventory/utils/JwtAuthenticationUtil.java +++ b/src/main/java/com/iemr/inventory/utils/JwtAuthenticationUtil.java @@ -112,15 +112,21 @@ private M_User fetchUserFromDB(String userId) { M_User user = userLoginRepo.getUserByUserID(Long.parseLong(userId)); if (user != null) { - // Cache the user in Redis for future requests (cache for 30 minutes) - redisTemplate.opsForValue().set(redisKey, user, 30, TimeUnit.MINUTES); + M_User userHash = new M_User(); + userHash.setUserID(user.getUserID()); + userHash.setUserName(user.getUserName()); + + // Cache the minimal user in Redis for future requests (cache for 30 minutes) + redisTemplate.opsForValue().set(redisKey, userHash, 30, TimeUnit.MINUTES); // Log that the user has been stored in Redis logger.info("User stored in Redis with key: " + redisKey); + + return user; } else { logger.warn("User not found for userId: " + userId); } - return user; + return null; } }