I have got a Spring Boot application that needs to take millions of key value pairs and insert them into Redis.
Currently I'm using the multiSet
method 1,000 key value pairs at a time.
@Autowired
private final StringRedisTemplate template;
...
Map<String, String> keyValuePairs = new HashMap<>();
template.opsForValue().multiSet(keyValuePairs);
However we also need to set a TTL for each pair. There doesn't seem to be a way to do this with multiSet
. There is a way with set
but this would have to be called millions of times so may not be efficient.
// For each key value pair
template.opsForValue().set(key, value, timeout, unit);
Does anyone know a way of doing this or using the set
in a performant way?
Thanks