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

Support redis lock automatic renewal #55

Merged
merged 5 commits into from
Dec 18, 2023

Conversation

starryrbs
Copy link

What does this do?

Support redis lock automatic renewal

Which issue(s) does this PR fix/relate to?

#54

List any changes that modify/break current functionality

Have you included tests for your changes?

TestAutoExtend

Did you document any new/modified functionality?

  • Updated example_test.go
  • Updated README.md

Notes

redislock.go Outdated
@@ -24,30 +25,31 @@ var (

// NewRedisLocker provides an implementation of the Locker interface using
// redis for storage.
func NewRedisLocker(r redis.UniversalClient, options ...redsync.Option) (gocron.Locker, error) {
func NewRedisLocker(r redis.UniversalClient, autoExtendDuration time.Duration, options ...redsync.Option) (gocron.Locker, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a breaking change (so let's not do it this way). An oversight on my part to have the options be ...resync.Option instead of a gocron.RedisLockerOption, to which we could just add WithAutoExtendDuration.

Instead, let's do it the way it should have been:

  • Add a new method func NewRedisLockerWithOptions(r redis.UniversalClient, options ...LockerOption) (gocron.Locker, error)
  • Define the LockerOption as type LockerOption func(*redisLocker) error
  • Then, we could define all the options, with Option appended to the name so they are unique, as LockerOption type
  • Then, also add WithAutoExtendDuration as an Option and implement it through there.

Let me know if you would like to complete this work. If not, I will take it on when I have time.

Copy link
Author

Choose a reason for hiding this comment

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

I made some changes:

  1. Add LockOption, support WithAutoExtendDuration,WithRedsyncOptions to be compatible with redsync options
  2. Added NewRedisLockerWithOptions
  3. Modified TestAutoExtend

Please review it again.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@JohnRoesler JohnRoesler merged commit 8542e0c into go-co-op:main Dec 18, 2023
3 checks passed
@starryrbs
Copy link
Author

Can you create a new tag? @JohnRoesler

@Sora233
Copy link

Sora233 commented Jan 18, 2024

Hi @JohnRoesler, sorry to bother, why this pr doesn't apply to the latest v2?

@JohnRoesler
Copy link
Contributor

@Sora233 it was added after I started the v2 branch. Feel free to make the same PR to the v2 branch - i will approve 👍

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.

3 participants