From f258f18c7bfdfc36b453a5527460f0a4d88e7cf9 Mon Sep 17 00:00:00 2001 From: chatgris Date: Thu, 5 Jul 2012 15:42:30 +0200 Subject: [PATCH] Added some colors to README. Signed-off-by: chatgris --- README.md | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a109b53..fa3a8f2 100644 --- a/README.md +++ b/README.md @@ -16,30 +16,38 @@ Usage Create a pool of objects to share amongst the fibers or threads in your Ruby application: - @memcached = ConnectionPool.new(:size => 5, :timeout => 5) { Dalli::Client.new } +``` ruby +@memcached = ConnectionPool.new(:size => 5, :timeout => 5) { Dalli::Client.new } +``` Then use the pool in your application: - @memcached.with_connection do |dalli| - dalli.get('some-count') - end +``` ruby +@memcached.with_connection do |dalli| + dalli.get('some-count') +end +``` You can use `ConnectionPool::Wrapper` to wrap a single global connection, making it easier to port your connection code over time: - $redis = ConnectionPool::Wrapper.new(:size => 5, :timeout => 3) { Redis.connect } - $redis.sadd('foo', 1) - $redis.smembers('foo') +``` ruby +$redis = ConnectionPool::Wrapper.new(:size => 5, :timeout => 3) { Redis.connect } +$redis.sadd('foo', 1) +$redis.smembers('foo') +``` The Wrapper uses `method_missing` to checkout a connection, run the requested method and then immediately check the connection back into the pool. It's **not** high-performance so you'll want to port your performance sensitive code to use `with_connection` as soon as possible. - $redis.with_connection do |conn| - conn.sadd('foo', 1) - conn.smembers('foo') - end +``` ruby +$redis.with_connection do |conn| + conn.sadd('foo', 1) + conn.smembers('foo') +end +``` Once you've ported your entire system to use `with`, you can simply remove ::Wrapper and use a simple, fast ConnectionPool.