Module: NetworkResiliency::Adapter::Redis

Extended by:
Redis
Included in:
Redis
Defined in:
lib/network_resiliency/adapter/redis.rb

Defined Under Namespace

Modules: Instrumentation

Instance Method Summary collapse

Instance Method Details

#patch(instance = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/network_resiliency/adapter/redis.rb', line 8

def patch(instance = nil)
  return if patched?(instance)

  if instance
    unless instance.is_a?(::Redis)
      raise ArgumentError, "expected Redis instance, found: #{instance}"
    end

    client = instance.instance_variable_get(:@client)

    unless client.is_a?(::Redis::Client)
      raise ArgumentError, "unsupported Redis client: #{client}"
    end

    client.singleton_class.prepend(Instrumentation)
  else
    ::Redis::Client.prepend(Instrumentation)
  end
end

#patched?(instance = nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/network_resiliency/adapter/redis.rb', line 28

def patched?(instance = nil)
  if instance
    client = instance.instance_variable_get(:@client)

    client && client.singleton_class.ancestors.include?(Instrumentation)
  else
    ::Redis::Client.ancestors.include?(Instrumentation)
  end
end