A Redis hash is a data type that represents a mapping between a string field and a string value which you can convert as list of any type of data
@RedisHash("User")
@Getter
@Setter
public class Student implements Serializable {
private String userId;
private String name;
private int age;
}
and then call it on repository
User user = User().builder.id("testUser").name("testName").age(20).expiration(86400).build(); userRepository.save(user);
You can also easily do this with Redis based framework - Redisson. It offers wrapped collections like java.util.List, java.util.Set, java.util.Map and many more.
Config config = ...
RedissonClient redisson = Redisson.create(config);
List<String> list = redisson.getList("myList");
list.add("1");
list.add("2");
list.add("3");
list.remove("2")