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

Add Redis Streams commands #319

Merged
merged 47 commits into from Jun 23, 2020

Conversation

Terkwood
Copy link
Contributor

@Terkwood Terkwood commented May 18, 2020

Description

This change set adds high-level wrappers for the Redis Streams commands (XREAD, XADD, etc). This is effectively a merge of https://github.com/grippy/redis-streams-rs into redis-rs.

Adds a feature streams which is turned on by default (following the example of geo). Adds tests for the new commands. Adds an example of usage.

Resolves #162.

These changes deliver a significant feature set which was requested in August 2018.

Task List

Attribution

This body of work was produced by @grippy and the contributors in https://github.com/grippy/redis-streams-rs. Thanks for making this available to the community!

@Terkwood Terkwood marked this pull request as ready for review May 18, 2020 21:24
@Terkwood Terkwood marked this pull request as draft May 18, 2020 21:25
@Terkwood Terkwood mentioned this pull request May 18, 2020
@grippy
Copy link
Contributor

grippy commented May 19, 2020

@Terkwood you rule! Thanks for porting this over. I'm taking a look now and will add comments if I see anything.

Copy link
Contributor

@grippy grippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good.

One small issue I have is there's a slight disconnect as to what each of these commands now returns if you're looking directly at the code for each new command. It might be worthwhile to add a few code examples on how to work with some of the commands that have custom reply types?

src/streams.rs Outdated Show resolved Hide resolved
@Terkwood
Copy link
Contributor Author

Adding an executable streams.rs example file sounds like a great idea, thanks!

src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Show resolved Hide resolved
src/streams.rs Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Show resolved Hide resolved
@Terkwood Terkwood marked this pull request as ready for review June 2, 2020 18:43
src/streams.rs Show resolved Hide resolved
@Terkwood Terkwood marked this pull request as ready for review June 8, 2020 16:42
src/streams.rs Show resolved Hide resolved
@Terkwood
Copy link
Contributor Author

Terkwood commented Jun 9, 2020

Is there any significant problem left with this change set which should prevent the merge?

Copy link
Collaborator

@Marwes Marwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
src/streams.rs Outdated Show resolved Hide resolved
@Terkwood
Copy link
Contributor Author

Terkwood commented Jun 9, 2020

Awesome -- thanks for the feedback! I'll work through these and hopefully have them finished by EOD. I've got a bunch of health-related junk coming up so this is my last chance to address issues before being forced to take a break!

@Terkwood
Copy link
Contributor Author

Terkwood commented Jun 9, 2020

OK, it looks like everything has been addressed, CI is passing, etc.

@grippy: There's some outstanding discussion on the usage of XCLAIM in the comment threads. Hopefully we can keep that as part of the PR, but if you have time, you might want to weigh in there, as it's the only place where we don't have 100% written consensus.

@Terkwood
Copy link
Contributor Author

Terkwood commented Jun 9, 2020

But I don't think we necessarily need additional input to move forward, if the response above satisfies you (Marwes). Presumably grippy favors the use of just_ids since it's his own creation.

It'll probably come as no surprise that I'm thus voting for an immediate merge 😉 This PR will unlock quite a bit of potential for other users to leverage the streams API from the comfort of their rust environment 🦀 🏞️

@grippy
Copy link
Contributor

grippy commented Jun 10, 2020

@Terkwood Sorry for the delay... It's been a while since I was in this code. As long as it matches the XCLAIM Redis command, I would vote for keeping JUSTID's as is.

@Terkwood
Copy link
Contributor Author

Thanks! 🌟

Terkwood added a commit to Terkwood/redis-rs that referenced this pull request Jun 13, 2020
@Terkwood
Copy link
Contributor Author

OK, the additional just_ids method is removed.

From the redis article:

JUSTID: Return just an array of IDs of messages successfully claimed, without returning the actual message. Using this option means the retry counter is not incremented.

So if you want the IDs only, and you want that specific behavior, you can get that. You can just pass the just_id option as true when you call our API.

pub struct StreamClaimOptions {
    /// Set IDLE <milliseconds> cmd arg.
    idle: Option<usize>,
    /// Set TIME <mstime> cmd arg.
    time: Option<usize>,
    /// Set RETRYCOUNT <count> cmd arg.
    retry: Option<usize>,
    /// Set FORCE cmd arg.
    force: bool,
    /// Set JUSTID cmd arg. Be advised: the response
    /// type changes with this option.
    justid: bool,
}

@Marwes was right to point out that the small helper method isn't strictly necessary, since the server can give us what we want. Also, I don't think the current state of the PR contradicts @grippy's previous comment -- as of the current commit, we expose all XCLAIM options.

Thanks again for being patient here, a lot of the comments I posted in the previous section were confused! 😁 But it's worth it, because we're within striking distance of having a big, new chunk of functionality exposed. Very much appreciate the input! 🌈

@Terkwood
Copy link
Contributor Author

I want to push at least one more test case up before we merge, so please sit tight...

@Terkwood
Copy link
Contributor Author

OK. It looks like just_ids is covered under test after all:

// claim and only return JUSTID
    let claimed: Vec<String> = con
        .xclaim_options(
            "k1",
            "g1",
            "c5",
            4,
            &claim_justids,
            StreamClaimOptions::default().with_force().with_justid(),
        )
        .unwrap();
    // we just claimed the original 10 ids
    // and only returned the ids
    assert_eq!(claimed.len(), 10);

So I will leave this PR in the hands of the maintainers, thanks! The review was very helpful.

Let us know if there are additional concerns that can be addressed! 🌤️

src/streams.rs Outdated
@@ -417,13 +417,6 @@ pub struct StreamKey {
pub ids: Vec<StreamId>,
}

impl StreamKey {
/// Return only the stream `id`'s without their data.
pub fn just_ids(&self) -> Vec<&String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually just pointed this out because users can do self.ids.iter().map(|msg| &msg.id) themselves, which is often more effecient since the Vec allocation can be avoided.

But hey, whatever works :)

@Marwes Marwes merged commit 3337c76 into redis-rs:master Jun 23, 2020
@Terkwood
Copy link
Contributor Author

Woo!!!! 🎉 🕺🏿 🥳

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

Successfully merging this pull request may close these issues.

Add support for streams
3 participants