Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

how to fetch single attribute from redis cache spring boot?

$
0
0

how to fetch a single attribute from Redis cache spring boot?

I want a response like this one

       {"answer": "FHFHFHFHFH"       }

but getting this one Please do let me know what should I do?

          {"questionId":58,"answer":"FHFHFHFHFH"          }

this is the response I am getting from the above API

below this code which I am using

Controller :->>>

          @GetMapping("/getAnswerStudentExam/{questionId}")          @ResponseBody         public ResponseEntity getAnswerStudentExam(@PathVariable Long           questionId){            System.out.println("getAnswerStudentExam  "+questionId);            QuentionCacheEntity item = answerCache.getAnswerStudent(questionId);         System.out.println("answerCache.getAnswerStudent(questionId); "+questionId);            return new ResponseEntity(item, HttpStatus.OK);         }

this API call this method

         @Cacheable(value = "ansCache", key = "#questionId")         public QuentionCacheEntity getAnswerStudent(Long questionId) {        QuentionCacheEntity answer = null;            try {            answer = ansQuestionRepo.getAnswerFromRedis(questionId);        } catch (Exception e) {            e.printStackTrace();        }        return answer;    }

this method will call this

          public QuentionCacheEntity getAnswerFromRedis(Long questionId){             return  (QuentionCacheEntity) hashOperations.get(KEY,questionId);         }

Below is model

code-->>>

          import java.io.Serializable;          import javax.persistence.Id;          import lombok.AllArgsConstructor;         import lombok.Data;       import lombok.NoArgsConstructor;        @Data        @NoArgsConstructor       @AllArgsConstructor       public class QuentionCacheEntity implements Serializable {      @Id        private Long questionId;        private String answer;       }

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>