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

Fix value conversion for CONFIG GET. #2381

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

Yury-Fridlyand
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand commented Oct 2, 2024

Multi-node RESP2 value wasn't converted

Fixes #2392

@Yury-Fridlyand Yury-Fridlyand added the Rust core redis-rs/glide-core matter label Oct 2, 2024
@Yury-Fridlyand Yury-Fridlyand requested a review from a team as a code owner October 2, 2024 01:59
@Yury-Fridlyand Yury-Fridlyand mentioned this pull request Oct 2, 2024
6 tasks
Copy link
Collaborator

@jonathanl-bq jonathanl-bq left a comment

Choose a reason for hiding this comment

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

A few small suggestions, but seems good otherwise.

// Second parameter is a function which returns true if value needs to be converted
SingleOrMultiNode(
&'a Option<ExpectedReturnType<'a>>,
Option<fn(Value) -> bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure how difficult it would be to change, but generally you should prefer taking a generic implementing a closure trait like F: Fn(Value) -> bool if possible because plain function pointers can't capture their environment like closures can. We don't really need the extra flexibility for our existing cases, so this isn't critical to do. Might not be worth making this change if it involves an extra Box alloc, but maybe worth a try at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean something like this?

pub(crate) enum ExpectedReturnType<'a, F: Fn(Value) -> bool> {
    Map {
        key_type: &'a Option<ExpectedReturnType<'a, F>>,
        value_type: &'a Option<ExpectedReturnType<'a, F>>,
    },
    // Second parameter is a function which returns true if value needs to be converted
    SingleOrMultiNode(
        &'a Option<ExpectedReturnType<'a, F>>,
        Option<F>,
    ),
...

(I also need to update all references to ExpectedReturnType type)
Or

pub(crate) enum ExpectedReturnType<'a> {
    Map {
        key_type: &'a Option<ExpectedReturnType<'a>>,
        value_type: &'a Option<ExpectedReturnType<'a>>,
    },
    // Second parameter is a function which returns true if value needs to be converted
    SingleOrMultiNode(
        &'a Option<ExpectedReturnType<'a>>,
        Option<&'a dyn Fn(Value) -> bool>,
    ),
...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking something more like the latter. I was actually expecting we'd take Box<dyn fn(Value) -> bool so we could own the closure, but we could probably get away with the reference instead. I'm aware this uses dynamic dispatch, but I think the performance hit is fairly negligible here.

glide-core/src/client/value_conversion.rs Outdated Show resolved Hide resolved
@Yury-Fridlyand Yury-Fridlyand linked an issue Oct 4, 2024 that may be closed by this pull request
@Yury-Fridlyand Yury-Fridlyand force-pushed the core/yuryf-fix-config-get branch 3 times, most recently from e51ad3c to 507f5f9 Compare October 15, 2024 23:19
@Yury-Fridlyand Yury-Fridlyand changed the base branch from main to release-1.2 October 15, 2024 23:19
@Yury-Fridlyand Yury-Fridlyand force-pushed the core/yuryf-fix-config-get branch from 507f5f9 to 0cbbde3 Compare October 15, 2024 23:20
@yipin-chen yipin-chen merged commit 54d624c into valkey-io:release-1.2 Dec 10, 2024
55 checks passed
@yipin-chen yipin-chen deleted the core/yuryf-fix-config-get branch December 10, 2024 18:42
barshaul pushed a commit to barshaul/glide-for-redis that referenced this pull request Dec 12, 2024
@Yury-Fridlyand Yury-Fridlyand mentioned this pull request Dec 17, 2024
Yury-Fridlyand added a commit to Bit-Quill/valkey-glide that referenced this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust core redis-rs/glide-core matter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CONFIG GET REPS2 multinode response isn't converted
3 participants