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; }