Моя конфигурация Redis:
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
@Bean
public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory cf) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(cf);
return template;
}
(я предлагаю изменить здесь Object на класс вашего класса сущности для сохранения)
Далее у меня есть два класса.Entity для сохранения и TestClass, как ваш класс "Burst".Не забудьте добавить во все классы сохранения реализует Сериализуемый .
public class TestEntity implements Serializable {
private String id;
private Map<Integer, TestClass> interal = new HashMap<>();
private Map<Integer, int[]> TWF;
// getters and setters
}
public class TestClass implements Serializable {
private String name;
// getters and setters
}
И код сохранения данных:
/* Initialize Hash operation*/
String KEY = "redis-map-key";
hashOperations = redisTemplate.opsForHash();
/* Fill Entity to save */
TestEntity testEntity = new TestEntity();
Map<Integer, int[]> mapWithArray = new HashMap<>();
int[] arr = {1, 5, 8};
mapWithArray.put(1, arr);
/* Internal class */
TestClass testClass = new TestClass();
testClass.setName("Test name");
Map<Integer, TestClass> internal = new HashMap<>();
internal.put(99, testClass);
/* Fill final object */
testEntity.setId("entity-id");
testEntity.setTWF(mapWithArray);
testEntity.setInteral(internal);
/* Save entity */
hashOperations.put(KEY, testEntity.getId(), testEntity);
/* Load entity */
TestEntity entityLoaded = (TestEntity) hashOperations.get(KEY, testEntity.getId());
System.out.println("Entity ID: " + entityLoaded.getId() + ", entity array: " + entityLoaded.getTWF());
RedisTemplate автоматически подключен.
Всеотлично работает и с другими типами из вашего класса (Date, int, boolean)