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 for Rails 7.1 -- rename to run_with #133

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/redlock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ def valid_lock?(lock_info)

class RedisInstance
module ConnectionPoolLike
def with
def run_with
yield self
end
Copy link
Owner

Choose a reason for hiding this comment

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

Do we still need to offer with? Is there any chance of breaking something?

        def with
          yield self
        end

        def run_with
          yield self
        end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its broken if we keep it. I think it should be just renamed. but the name might not be your favorite..

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you @mathieujobin

end

def initialize(connection)
if connection.respond_to?(:with)
if connection.respond_to?(:run_with)
@redis = connection
else
if connection.respond_to?(:client)
Expand All @@ -168,15 +168,15 @@ def initialize(connection)

def lock(resource, val, ttl, allow_new_lock)
recover_from_script_flush do
@redis.with { |conn|
@redis.run_with { |conn|
conn.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock)
}
end
end

def unlock(resource, val)
recover_from_script_flush do
@redis.with { |conn|
@redis.run_with { |conn|
conn.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val)
}
end
Expand All @@ -186,7 +186,7 @@ def unlock(resource, val)

def get_remaining_ttl(resource)
recover_from_script_flush do
@redis.with { |conn|
@redis.run_with { |conn|
conn.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource)
}
end
Expand All @@ -203,7 +203,7 @@ def load_scripts
Scripts::PTTL_SCRIPT
]

@redis.with do |connnection|
@redis.run_with do |connnection|
scripts.each do |script|
connnection.call('SCRIPT', 'LOAD', script)
end
Expand Down