I am using RedisTemplate in my spring boot application and I am able to read using singleKey.
String valueJson = (String) redisTemplate.opsForValue().get(setKey(someId));
I have now a List of "someId" like "List someIds" and I want to get the data of all Ids. Of course I can iterate on the list and hit redis with indivisual keys, but I dont want that, instead I want provide the whole list to get the response in one go.
Please help.
You need to use pipelining: https://redis.io/topics/pipelining
List<Object> results = redisTemplate.executePipelined(
new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisConnection stringRedisConn = (StringRedisConnection)connection;
for(String id:someIds)
stringRedisConn.get(id);
return null;
}
});
Or in Java 8:
List<Object> results = redisTemplate.executePipelined((RedisCallback<Object>) connection -> {
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
someIds.forEach(id -> {
stringRedisConn.get(id);
});
return null;
});
The results List will contain all that you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With