Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline is invalid #3872

Closed
zymgg opened this issue Jun 26, 2024 · 2 comments
Closed

Pipeline is invalid #3872

zymgg opened this issue Jun 26, 2024 · 2 comments

Comments

@zymgg
Copy link

zymgg commented Jun 26, 2024

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();
@sazzad16
Copy link
Collaborator

@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.

@zymgg
Copy link
Author

zymgg commented Jun 26, 2024

@sazzad16 Sorry, perhaps I misunderstood the principle of Redis pipeline。
I tested the time consumption with and without using the pipeline,
Which proved that the pipeline is effective!
thanks for your answer!

@zymgg zymgg closed this as completed Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants