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 Script::load function #603

Merged
merged 4 commits into from Jun 9, 2022
Merged

Conversation

zhiburt
Copy link
Contributor

@zhiburt zhiburt commented May 5, 2022

Hi there

This PR exposes a load function to not do it manually.
It also changes a repeat logic in sync version of Script::invoke to limit the repeat cycle to 2 attempts (The same way as is done in async version).

Take care.

Make it work the same in case of async and sync version.

Potentially the old version was causing a infinite loop in case the redis is endlessly FLUSHed?

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
@zhiburt
Copy link
Contributor Author

zhiburt commented May 10, 2022

Hi @djc as I see you've run the CI.
Could you make one more attempt?
I hope I've fixed the build.

@zhiburt zhiburt force-pushed the add-script-load-function branch 2 times, most recently from 95f2d67 to 36fee9d Compare May 11, 2022 07:26
@zhiburt
Copy link
Contributor Author

zhiburt commented May 11, 2022

Sorry.....
one more time, please?

*It must be it

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

Thanks, this mostly looks good!

} else {
fail!(err);
}
let mut eval_cmd = cmd("EVALSHA");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you think we no longer need the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you may see that a sync and async implementation is different.
I think that the async implementation with 1 retry is better. So I replace a loop implementation with it.

The loop may cause a number of retries or even "potentially" an infinite loop.
See when there's no script LOADed we load it, but then if someone FLUSHes redis EVAL will be an error an we will try to LOAD the script one more time.

Also it's beneficial because the unification of the code.

src/script.rs Show resolved Hide resolved
src/script.rs Show resolved Hide resolved

let hash = script.prepare_invoke().load_async(&mut con);
assert_eq!(hash, Ok(script.get_hash().to_string()));
let mut con = ctx.multiplexed_async_connection_async_std().await.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change these to unwrap()?

Copy link
Contributor Author

@zhiburt zhiburt May 12, 2022

Choose a reason for hiding this comment

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

To fix the build :) (I may mistaken but it was necessary to specify a Result::Err type)

Do you think it matters?

@jaymell jaymell merged commit bb329dd into redis-rs:main Jun 9, 2022
nonirosenfeldredis pushed a commit to nonirosenfeldredis/redis-rs that referenced this pull request Feb 13, 2023
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.

None yet

3 participants