I want response from redis cli to postman as this
http://localhost:8585/api/home/getBestTrainerBasedRating
[
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 0.0,
"image": "null",
"language": "kannada"
},
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 0.0,
"image": "null",
"language": "telugu"
},
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 6.0,
"image": "null",
"language": "kannada"
},
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 6.0,
"image": "null",
"language": "telugu"
},
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 10.0,
"image": "null",
"language": "kannada"
},
{
"trainerid": 28,
"rating": 5.0,
"trainerName": "yellow",
"courseName": "",
"price": 10.0,
"image": "null",
"language": "telugu"
}
]
But I am getting this response http://localhost:8585/api/redishome/redisGetBestTrainerBasedRating
{
"message": "Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.List com.mycareerbuild.user.cache.HomeControllerCache.getBestTrainerBasedRatingFromRedis()] caches=[homeCache] | key='#getratinghome' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'"
}
This is my Controller
@RestController
@RequestMapping("/api/redishome")
public class HomeRedisController {
@Autowired
HomeControllerCache hc;
@Autowired
private HomeService homeService;
private static final Logger logger = LogManager.getLogger(HomeRedisController.class);
@GetMapping("/redisGetBestTrainerBasedRating")
@ResponseBody
public ResponseEntity<List<BestTrainerBasedRating>> RedisgetBestTrainerBasedRating()
throws RecordNotFoundException {
logger.info("started RedisgetBestTrainerBasedRating method in controller");
List<BestTrainerBasedRating> trainerCourse = hc.getBestTrainerBasedRatingFromRedis();
logger.info("end RedisgetBestTrainerBasedRating method in controller");
return new ResponseEntity<List<BestTrainerBasedRating>>(trainerCourse, new HttpHeaders(),
HttpStatus.OK);
}}
this is my cache component
@Component
public class HomeControllerCache {
@Autowired
HomeControllerCacheRepo cacheRepo;
@Autowired
private HomeRepository homeRepo;
@Cacheable(value="homeCache" ,key="#getratinghome")
public List<BestTrainerBasedRating> getBestTrainerBasedRatingFromRedis() {
List<BestTrainerBasedRating> ratingD = null;
try {
ratingD = cacheRepo.getBestTrainerBasedRating();
} catch (Exception e) {
e.printStackTrace();
}
return ratingD;
} }
this is my cache repo
@Repository
public class HomeControllerCacheRepo {
public static final String KEY = "HOME";
private RedisTemplate<String, BestTrainerBasedRating> redisTemplate;
[enter image description here][1] private HashOperations hashOperations;
public HomeControllerCacheRepo(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
}
/*Getting a specific item by item id from table*/
public List<BestTrainerBasedRating> getBestTrainerBasedRating(){
return ( List<BestTrainerBasedRating>) hashOperations.get(KEY, hashOperations);
}}
I have attached redis cli image please check