I would like to retrieve multiple hashmap values with only specified fields. So I opted-in to Redis pipeline.
While testing the below code, i see redisResponse1
is always null, where as redisResponse2
has value.
getRedisTemplate().executePipelined(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
List<byte[]> redisResponse1 = connection.hMGet(key.getBytes(), params);
List<byte[]> redisResponse2 = getRedisTemplate().getConnectionFactory().getConnection().hMGet(key.getBytes(), specificParams);
return null;
}
});
When I look into the code and found that below, where
a) redisResponse2
is not executed with pipeline option
b) redisResponse1
is executed with pipeline (isPipelined() == true) but returning always null.
public List<byte[]> hMGet(byte[] key, byte[]... fields) {
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.hmget(key, fields)));
return null;
}
if (isQueueing()) {
transaction(new JedisResult(transaction.hmget(key, fields)));
return null;
}
return jedis.hmget(key, fields);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
So questions are
1) How do I achieve my use case with pipeline option?
2) What is the impact accessing getRedisTemplate().getConnectionFactory().getConnection()
within this RedisCallback?
3) How this whole pipeline concept is working? Is it like dynamic Lua? where this Java code is converted as Lua script and send to Redis as script, executed in Redis and come back? Surprised on within this callback; the code is accessing/updating the outer class variables as well, so what will happen to all that variables? All those outer class variables also send to redis in lua?
4) I see many examples about doInRedis
API is returning null
; Why so? How to return/get valid Object from that?