Reputation: 45
I using redis caching my project but i have a problem. I had model student and write method put it to redis.First method i write findStudent one week and put it to cache.
public void findStudentOneWeek(List<Student> students1) {
redistemplate.opsForHash().put("Student", student.getId(), List<Customers>);
}
Second method I write findStudent one day.
public void findStudentOneDay(List<Student> students2) {
redistemplate.opsForHash().put("Student", student.getId(), List<Customers>);
}
But i want total user from 8 day. It mean i want hold one key Student but new value equal total value method findStudentOneWeek + total value method findStudentOneDay. But i don't now how to do. I can't find method working it. I know method put from redis but it remove old value and save new value. I don't want it. I want value total.
Upvotes: 1
Views: 3117
Reputation: 44398
Firstly, I assume a typo, where List<Customers>
should be List<Students> student
:
redistemplate.opsForHash().put("Student", student.getId(), List<Students> students);
Spring Data class HashOperations
works on the similar principle as HashMap
. Both allow you to get the value by the key (and the hash key in case of HashOperations
). Read the current value List<Customers>
and put them with a new value to the template.
List<Students> students = redistemplate.opsForHash().get("Student", student.getId());
students2.addAll(students);
redistemplate.opsForHash().put("Student", student.getId(), students2);
Upvotes: 1