Pipeline is invalid
zymgg opened this issue · comments
version
springboot:2.7.12
jedis:5.1.3
I am used the pipeline batch send command, But i found that jedis is insertd into Redis one bye one
Why it cant not batch inset
@Bean
public UnifiedJedis unifiedJedis() {
HostAndPort config = new HostAndPort(host, port);
PooledConnectionProvider provider = new PooledConnectionProvider(config);
UnifiedJedis unifiedJedis = new JedisPooled(provider);
if (StringUtils.isNotBlank(password)) {
unifiedJedis.sendCommand(Protocol.Command.AUTH, password);
}
return unifiedJedis;
}
AbstractPipeline pipeline = unifiedJedis.pipelined();
for (Goods goods : goodsList) {
String picUrl = goods.getPicUrl();
try {
Goods updateGoods = new Goods();
updateGoods.setId(goods.getId());
Float[] floats = predictImage(picUrl);
updateGoods.setPictureFeatureVector(floats);
goods.setPictureFeatureVector(floats);
pipeline.hset(GOODS + goods.getId(), beanToMap(goods));
pipeline.hset((GOODS + goods.getId()).getBytes(), (goodsPictureFeatureVectorFieldName + "Bytes").getBytes(),
floatArrayToByteArray(goods.getPictureFeatureVector()));
updateGoods.setPictureFeatureVector(floats);
updateGoodsList.add(updateGoods);
} catch (Exception e) {
log.error("init picture vector:" + picUrl, e);
}
}
batchOperate(null, updateGoodsList);
pipeline.sync();
@zymgg Sorry, I am having difficulty understanding your question but still trying to answer.
Pipeline is a form of batching. But if you mean batching at server side, Redis doesn't exactly have that. Closest thing it has is Transaction (MULTI/EXEC). Jedis supports that feature by Transaction / ReliableTransaction classes.