-
Notifications
You must be signed in to change notification settings - Fork 81
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
Plan for switching to RedisClient #121
Comments
I think it already works, have you tried the following code snippet replacing servers = [ 'redis://localhost:6379', Redis.new(:url => 'redis://someotherhost:6379') ]
redlock = Redlock::Client.new(servers) |
Thanks @leandromoreira. So, the interface will need some adjustments, AFAIS, "only in" def lock(resource, val, ttl, allow_new_lock)
recover_from_script_flush do
- @redis.with { |conn| conn.evalsha Scripts::LOCK_SCRIPT_SHA, keys: [resource], argv: [val, ttl, allow_new_lock] }
+ @redis.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| conn.evalsha Scripts::UNLOCK_SCRIPT_SHA, keys: [resource], argv: [val, ttl] }
+ @redis.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val)
end
rescue
# Nothing to do, unlocking is just a best-effort attempt.
end
def get_remaining_ttl(resource)
recover_from_script_flush do
- @redis.with { |conn| conn.evalsha Scripts::PTTL_SCRIPT_SHA, keys: [resource] }
+ @redis.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource)
end
rescue Redis::BaseConnectionError
nil
end |
Other gems, including sidekiq, have moved over; So this is becoming out of sync |
Thanks @san983 and @sirwolfgang go ahead and implement that! I'm glad you're offering to do that. Maybe we could introduce a new wrapper client abstraction interface with the default implementation being the class RedisClientWrapper
def lock_call(resource, val, ttl, allow_new_lock)
recover_from_script_flush do
@redis_client.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock)
end
end
# ...
end
class RedisWrapper
def lock_call(redis_client, resource, val, ttl, allow_new_lock)
recover_from_script_flush do
@redis_client.with { |conn| conn.evalsha Scripts::UNLOCK_SCRIPT_SHA, keys: [resource], argv: [val, ttl] }
end
end
# ...
end
# ... and then replace the places where it's should rely on redis client
# and somehow offer a way for the user to pass their own redis client wrapper
def lock(resource, val, ttl, allow_new_lock)
@redlock_wrapper.lock_call(resource, val, ttl, allow_new_lock)
end But maybe this effort is too much and not so useful, what do you think? |
Judging from how quickly people are migrating, I think the general consensus is that supporting both isn't necessary. It's likely prudent to just cut a breaking change, with the client updated. |
@leandromoreira I just pushed a pass at setting up a PR for this, as version I do think some consideration needs to be made around the initialization interface. Based on upgrading to sidekiq 7, I suspect that we want to actually drop This I think makes the two interfaces of either providing a premade |
The built in pooler is compatible with the |
Thank @sirwolfgang I'll look at right now! |
Hi! Is there any plan or roadmap to move to https://github.com/redis-rb/redis-client that I can contribute to?
The text was updated successfully, but these errors were encountered: