Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.gs
/Gemfile.lock
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: ruby
rvm:
- 2.2.1
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/redic/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require "redic"

class Redic::Pool
VERSION = "1.0.1"

attr :url
attr :pool

Expand All @@ -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] = [])
Expand Down
6 changes: 6 additions & 0 deletions lib/redic/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Redic
class Pool
# Current gem version
VERSION = "1.0.1"
end
end
11 changes: 7 additions & 4 deletions redic-pool.gemspec
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions test/ohm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
22 changes: 11 additions & 11 deletions test/pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
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")

teardown(r)
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")
r.queue("EXEC")

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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/prelude.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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