Skip to content

Instantly share code, notes, and snippets.

@roidrage
Last active November 11, 2016 18:49
Show Gist options
  • Save roidrage/4721985 to your computer and use it in GitHub Desktop.
Save roidrage/4721985 to your computer and use it in GitHub Desktop.
require 'connection_pool'
require 'redis'
require 'metriks'
class RedisClientWrapper
def initialize(options)
@options = options.delete(:pool)
@pool = ConnectionPool.new(@options) do
::Redis.new(options)
end
end
def method_missing(name, *args)
@pool.with do |redis|
if redis.respond_to?(name)
Metriks.timer("redis.operations.#{name}").time do
redis.send(name, *args)
end
else
super
end
end
end
end
redis = RedisClientWrapper.new(pool: {size: 50, timeout: 10})
@badboy
Copy link

badboy commented Feb 6, 2013

Shouldn't @options be used somewhere?

@roidrage
Copy link
Author

roidrage commented Feb 7, 2013

@badboy it should indeed! fixed the code, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment