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

RedisStreamPublisher list publish alternative #691

Closed
Balazs-Joo opened this issue Aug 1, 2024 · 0 comments · Fixed by #729
Closed

RedisStreamPublisher list publish alternative #691

Balazs-Joo opened this issue Aug 1, 2024 · 0 comments · Fixed by #729
Assignees
Labels
enhancement New feature or request

Comments

@Balazs-Joo
Copy link
Contributor

Balazs-Joo commented Aug 1, 2024

protected List<Optional<StreamEntryID>> publishInActiveConnection(String streamGroup, List<String> streamMessages, Map<String, String> parameters)

This method uses for and publishes messages individual.

Would be great if there where an alternative method using Jedis Pipeline.

@Test
void test() throws BaseException {
    List<String> ids = IntStream.range(0, 5000).mapToObj(i -> RandomUtil.generateId()).toList();
    Jedis jedis = new Jedis("localhost", 6379);

    String streamKey = "mystream";

    long startTime = System.currentTimeMillis();
    for (var id : ids) {
        Map<String, String> message = new HashMap<>();
        message.put("message_id", id);
        message.put("content", id);
        jedis.xadd(streamKey, (StreamEntryID) null, message);
    }

    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    Pipeline pipeline = jedis.pipelined();

    startTime = System.currentTimeMillis();
    for (var id : ids) {
        Map<String, String> message = new HashMap<>();
        message.put("message_id", id);
        message.put("content", id);
        pipeline.xadd(streamKey, (StreamEntryID) null, message);
    }

    List<Object> responses = pipeline.syncAndReturnAll();

    System.out.println("Pipelined Elapsed time: " + (System.currentTimeMillis() - startTime));

    jedis.close();
}

The result of this test
Elapsed time: 221
Pipelined Elapsed time: 23

@Balazs-Joo Balazs-Joo added the enhancement New feature or request label Aug 1, 2024
@plevente011230 plevente011230 self-assigned this Oct 18, 2024
plevente011230 added a commit that referenced this issue Dec 12, 2024
@rombow rombow linked a pull request Dec 12, 2024 that will close this issue
plevente011230 added a commit that referenced this issue Dec 16, 2024
…-RedisStreamPublisher-list-publish-alternative

#691 RedisStreamPublisher pipelined publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants