Changes for BAEL-1472
This commit is contained in:
+6
-3
@@ -1,8 +1,5 @@
|
||||
package com.baeldung.spring.data.redis.config;
|
||||
|
||||
import com.baeldung.spring.data.redis.queue.MessagePublisher;
|
||||
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
||||
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -11,10 +8,16 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.listener.ChannelTopic;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
|
||||
import com.baeldung.spring.data.redis.queue.MessagePublisher;
|
||||
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
||||
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.spring.data.redis")
|
||||
@EnableRedisRepositories(basePackages = "com.baeldung.spring.data.redis.repo")
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
|
||||
+3
@@ -2,6 +2,9 @@ package com.baeldung.spring.data.redis.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.data.redis.core.RedisHash;
|
||||
|
||||
@RedisHash("Student")
|
||||
public class Student implements Serializable {
|
||||
|
||||
public enum Gender {
|
||||
|
||||
+5
-14
@@ -1,18 +1,9 @@
|
||||
package com.baeldung.spring.data.redis.repo;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.spring.data.redis.model.Student;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface StudentRepository {
|
||||
|
||||
void saveStudent(Student person);
|
||||
|
||||
void updateStudent(Student student);
|
||||
|
||||
Student findStudent(String id);
|
||||
|
||||
Map<Object, Object> findAllStudents();
|
||||
|
||||
void deleteStudent(String id);
|
||||
}
|
||||
@Repository
|
||||
public interface StudentRepository extends CrudRepository<Student, String> {}
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
package com.baeldung.spring.data.redis.repo;
|
||||
|
||||
import com.baeldung.spring.data.redis.model.Student;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public class StudentRepositoryImpl implements StudentRepository {
|
||||
|
||||
private static final String KEY = "Student";
|
||||
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
private HashOperations hashOperations;
|
||||
|
||||
@Autowired
|
||||
public StudentRepositoryImpl(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hashOperations = redisTemplate.opsForHash();
|
||||
}
|
||||
|
||||
public void saveStudent(final Student student) {
|
||||
hashOperations.put(KEY, student.getId(), student);
|
||||
}
|
||||
|
||||
public void updateStudent(final Student student) {
|
||||
hashOperations.put(KEY, student.getId(), student);
|
||||
}
|
||||
|
||||
public Student findStudent(final String id) {
|
||||
return (Student) hashOperations.get(KEY, id);
|
||||
}
|
||||
|
||||
public Map<Object, Object> findAllStudents() {
|
||||
return hashOperations.entries(KEY);
|
||||
}
|
||||
|
||||
public void deleteStudent(final String id) {
|
||||
hashOperations.delete(KEY, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user