-
Notifications
You must be signed in to change notification settings - Fork 1
/
StudentRep.java
58 lines (36 loc) · 1.23 KB
/
StudentRep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.demir.redis.repository;
import com.demir.redis.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class StudentRep {
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate template;
private String HASH_KEY = "Student";
public Student addStudent(Student student){
template.opsForHash().put(HASH_KEY, student.getId(), student);
return student;
}
public Student updateStudent(Student student) {
template.opsForHash().put(HASH_KEY, student.getId(), student);
return student;
}
public List<Student> getAll(){
return template.opsForHash().values(HASH_KEY);
}
public Student getStudentId(String id){
return (Student) template.opsForHash().get(HASH_KEY,id);
}
public String deleteStudent(String id){
try{
template.opsForHash().delete(HASH_KEY, id);
return "Student delete";
}catch (Exception e){
return e.toString();
}
}
}