Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Novikov <[email protected]>
  • Loading branch information
palkan and Envek authored Aug 13, 2024
1 parent b2d23f2 commit 5947128
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/graphql-anycable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def stats(**opts)
Stats.new(**opts).collect
end

def redis
warn "Usage of `GraphQL::AnyCable.redis` is deprecated. Instead of `GraphQL::AnyCable.redis.whatever` use `GraphQL::AnyCable.with_redis { |redis| redis.whatever }`"
@redis ||= with_redis { |conn| conn }
end

def redis=(connector)
@redis_connector = if connector.is_a?(::Proc)
connector
Expand All @@ -30,7 +35,7 @@ def redis=(connector)

def with_redis(&block)
@redis_connector || default_redis_connector
@redis_connector.call { |conn| block.call(conn) }
@redis_connector.call(&block)
end

def config
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/subscriptions/anycable_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def delete_channel_subscriptions(channel)

private

def delete_subscription(redis, subscription_id)
def delete_subscription(subscription_id, redis: with_redis { |conn| conn }))
events = redis.hget(redis_key(SUBSCRIPTION_PREFIX) + subscription_id, :events)
events = events ? JSON.parse(events) : {}
fingerprint_subscriptions = {}
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/anycable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
)
end

let(:redis) { AnycableSchema.subscriptions.with_redis { _1 } }
let(:redis) { $redis }

subject do
AnycableSchema.subscriptions.delete_channel_subscriptions(channel)
Expand Down
2 changes: 1 addition & 1 deletion spec/redis_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

RSpec.configure do |config|
config.before do
GraphQL::AnyCable.with_redis { _1.flushdb }
GraphQL::AnyCable.with_redis(&:flushdb)
end
end

0 comments on commit 5947128

Please sign in to comment.