Configure and Use Spring Data Redis


public class RedisConfiguration {

    public LettuceConnectionFactory redisConnectionFactory() {
        ConfigFile configFile = new ConfigFile();
        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(configFile.getRedisHost());
        return new LettuceConnectionFactory(configuration);

    public StringRedisTemplate redisTemplate() {
        return new StringRedisTemplate(redisConnectionFactory());

You can use RedisTemplate instead of StringRedisTemplate.

Redis Repository

public class Student implements Serializable {
    public enum Gender { 
        MALE, FEMALE

    @Id private String id;
    private String name;
    private Gender gender;
    private int grade;
    // ...

The Spring Data Repository

public interface StudentRepository extends CrudRepository<Student, String> {}

Data Access Using StudentRepository

Saving a New Student Object

Student student = new Student(
  "Eng2015001", "John Doe", Student.Gender.MALE, 1);;

Retrieving an Existing Student Object

Student retrievedStudent = 

Updating an Existing Student Object

retrievedStudent.setName("Richard Watson");;

Deleting Existing Student Data


Find All Student Data

Student engStudent = new Student(
  "Eng2015001", "John Doe", Student.Gender.MALE, 1);
Student medStudent = new Student(
  "Med2015001", "Gareth Houston", Student.Gender.MALE, 2);;;