diff --git a/.gitignore b/.gitignore index 06c6afe..9cb9f59 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.gs +/Gemfile.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a642ae0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: ruby +rvm: + - 2.2.1 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b4e2a20 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec diff --git a/README.md b/README.md index ae59ce0..a6434e2 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ Usage Array.new(100) do Thread.new do - $redis.call("GET", "foo") + $redis.call!("GET", "foo") end end.each(&:join) - $redis.call("INFO", "clients")[/connected_clients:(\d+)/, 1] + $redis.call!("INFO", "clients")[/connected_clients:(\d+)/, 1] # => "10" With Ohm diff --git a/lib/redic/pool.rb b/lib/redic/pool.rb index 4acf428..25f83a3 100644 --- a/lib/redic/pool.rb +++ b/lib/redic/pool.rb @@ -2,8 +2,6 @@ require "redic" class Redic::Pool - VERSION = "1.0.1" - attr :url attr :pool @@ -19,6 +17,7 @@ def call(*args) client.call(*args) end end + alias_method :call!, :call def queue(*args) Thread.current[@id] || (Thread.current[@id] = []) diff --git a/lib/redic/version.rb b/lib/redic/version.rb new file mode 100644 index 0000000..d98f12d --- /dev/null +++ b/lib/redic/version.rb @@ -0,0 +1,6 @@ +class Redic + class Pool + # Current gem version + VERSION = "1.0.1" + end +end diff --git a/redic-pool.gemspec b/redic-pool.gemspec index 4f700d8..4173c77 100644 --- a/redic-pool.gemspec +++ b/redic-pool.gemspec @@ -1,7 +1,8 @@ -require "./lib/redic/pool" +require "./lib/redic/version" Gem::Specification.new do |s| s.name = "redic-pool" + s.description = "A Redis connection pool using Redic" s.version = Redic::Pool::VERSION @@ -19,8 +20,10 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- test/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } - s.add_dependency("connection_pool") - s.add_dependency("redic") + s.add_runtime_dependency 'redic', '~> 1.5', '>= 1.5.0' + s.add_runtime_dependency 'connection_pool', '~> 2.2', '>= 2.2.0' - s.add_development_dependency("cutest") + s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2' + s.add_development_dependency 'cutest', '~> 1.2', '>= 1.2.2' + s.add_development_dependency 'ohm', '~> 2.3', '>= 2.3.0' end diff --git a/test/ohm_test.rb b/test/ohm_test.rb index 19082de..97b1e06 100644 --- a/test/ohm_test.rb +++ b/test/ohm_test.rb @@ -26,7 +26,7 @@ class Comment < Ohm::Model threads.each(&:join) - clients = Parsers.info(Ohm.redis.call("INFO", "clients")).fetch("connected_clients") + clients = Parsers.info(Ohm.redis.call!("INFO", "clients")).fetch("connected_clients") assert_equal(clients, "10") @@ -45,7 +45,7 @@ class Comment < Ohm::Model threads.each(&:join) - clients = Parsers.info(Ohm.redis.call("INFO", "clients")).fetch("connected_clients") + clients = Parsers.info(Ohm.redis.call!("INFO", "clients")).fetch("connected_clients") assert_equal(clients, "10") end diff --git a/test/pool_test.rb b/test/pool_test.rb index 7398f0d..b1a0d94 100644 --- a/test/pool_test.rb +++ b/test/pool_test.rb @@ -8,14 +8,14 @@ threads = Array.new(100) do Thread.new do 10.times do - r.call("GET", "foo") + r.call!("GET", "foo") end end end threads.each(&:join) - clients = Parsers.info(r.call("INFO", "clients")).fetch("connected_clients") + clients = Parsers.info(r.call!("INFO", "clients")).fetch("connected_clients") assert_equal(clients, "10") @@ -23,9 +23,9 @@ end test "MULTI return value with WATCH" do |r| - r.call("DEL", "foo") + r.call!("DEL", "foo") - r.call("WATCH", "foo", "bar") + r.call!("WATCH", "foo", "bar") r.queue("MULTI") r.queue("SET", "foo", "bar") @@ -33,17 +33,17 @@ assert_equal(r.commit.last, ["OK"]) - assert_equal(r.call("GET", "foo"), "bar") + assert_equal(r.call!("GET", "foo"), "bar") teardown(r) end test "Pipelining" do |r| - r.call("DEL", "foo") + r.call!("DEL", "foo") r.queue("SET", "foo", "bar") - assert_equal nil, r.call("GET", "foo") + assert_equal nil, r.call!("GET", "foo") teardown(r) end @@ -52,9 +52,9 @@ threads = Array.new(100) do Thread.new do 10.times do - r.call("SET", "foo", "bar") + r.call!("SET", "foo", "bar") - r.call("DEL", "foo") + r.call!("DEL", "foo") end end end @@ -71,10 +71,10 @@ threads.each(&:join) - clients = Parsers.info(r.call("INFO", "clients")).fetch("connected_clients") + clients = Parsers.info(r.call!("INFO", "clients")).fetch("connected_clients") assert_equal(clients, "10") - assert_equal(r.call("GET", "foo"), nil) + assert_equal(r.call!("GET", "foo"), nil) teardown(r) end diff --git a/test/prelude.rb b/test/prelude.rb index 19cacf0..9b144ec 100644 --- a/test/prelude.rb +++ b/test/prelude.rb @@ -23,5 +23,5 @@ def self.info(reply) sleep(0.5) def teardown(r) - r.pool.shutdown { |c| c.call("QUIT") } + r.pool.shutdown { |c| c.call!("QUIT") } end