redic-pool 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGMwN2MxMjRiMzExYWE3YzIwNmIzOGQ5MGM0ZTVkMjEwYTkzYWQ4NA==
4
+ MWY0MzFlY2M4MWFjZTBkNmMwYzVlMjY5ZjI1NTUzZmE0OWQzMzg2Nw==
5
5
  data.tar.gz: !binary |-
6
- MjUwMDgzYmY0YjA1MzI2Y2M3MzU2OTE4NmVmNmVlODExMDIyMmNiNg==
6
+ Y2Y1ZmM0NTQ0N2VlNjBlNDU3MmM2OWY0ZmVkYWNlZmI5OGEwN2M4NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjA5NjdjYjg0YjY0Y2U4YmQ5MTNkMTYzNWM4YTc3ZTc0Nzc3M2IzZTI0Y2Qx
10
- MzFlOGE1MjkzMzc4NjlkODlkZGY5ZGFjMmRiOTBjZWU2NDc4YjczNzAzMDgz
11
- YWRjNzljMjhlOGI2NjkxMTFjOTc0NDU3YTQ1NDlhMTlkY2EyN2M=
9
+ ZWUzZmEyNGNmYjIzNGYyNzA3M2VlM2ZlZWY4NWZhMGE2ZjM2ZjZiYWMwNDFh
10
+ MzZlMzMxMzZkYmUyZjA1ZTVkNzg5ZmNjOWNiYWJhMjQwNjE2ZWM3ZjdkM2Ew
11
+ NmM4ZDQzNDMzZWQ0Y2ZmODA5YTk0YzY1YTE0OWVjYWUyNDcwOTk=
12
12
  data.tar.gz: !binary |-
13
- ZTkyYWY5NzhlZjU3ODgzODliY2IzNDVjZTRjODJkMTkyMTdjN2IxYmE2ZTIz
14
- M2U1NzcwNzkwZDFmOGIwZmRjMzgyYjY5OTcwZmJmM2ViOGVmMjkxZGUwMGEy
15
- MzJhODg0MjRmNTE0NTE5MDAyOWMzZWI0Y2M2NWIyMWY1MDVjOTY=
13
+ NjgxM2JjZGZlYjhlOGQzOGZhYTc1NTc0MWQzOTViNDg4OTFkOGM5YzRlZGYy
14
+ OGNmMmVlY2Q2NTExZWYxOTA0MmQxOTUwM2FiM2JjNzc1NDg4YWJhNjkwZmJk
15
+ NTAxYzM3OWU1ZGY4MWVjNmRlNzkyZDI3NWVkMDg4NmY2YjcxOWU=
@@ -1,3 +1,11 @@
1
+ 1.0.0 - 2013-12-27
2
+ ==================
3
+
4
+ * Changed API to make a `Redic::Pool` object interchangeable with `Redic`. This
5
+ makes `Redic::Pool` compatible with Ohm out of the box, so you can do:
6
+
7
+ Ohm.redis = Redic::Pool.new(ENV["REDIS_URL"], size: 10)
8
+
1
9
  0.1.0 - 2013-12-18
2
10
  ==================
3
11
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Redic::Pool
2
2
  ===========
3
3
 
4
- A Redis connection pool using [Redis](https://github.com/amakawa/redic).
4
+ A Redis connection pool using [Redic](https://github.com/amakawa/redic).
5
5
 
6
6
  Usage
7
7
  -----
@@ -2,12 +2,16 @@ require "connection_pool"
2
2
  require "redic"
3
3
 
4
4
  class Redic::Pool
5
- VERSION = "0.1.0"
5
+ VERSION = "1.0.0"
6
6
 
7
+ attr :url
7
8
  attr :pool
8
9
 
9
10
  def initialize(url, options = {})
11
+ @url = url
10
12
  @pool = ConnectionPool.new(size: options.fetch(:size, 10)) { Redic.new(url) }
13
+
14
+ @id = "redic-pool-#{object_id}"
11
15
  end
12
16
 
13
17
  def call(*args)
@@ -16,7 +20,18 @@ class Redic::Pool
16
20
  end
17
21
  end
18
22
 
19
- def with(&block)
20
- @pool.with(&block)
23
+ def queue(*args)
24
+ Thread.current[@id] || (Thread.current[@id] = [])
25
+ Thread.current[@id] << args
26
+ end
27
+
28
+ def commit
29
+ @pool.with do |client|
30
+ Thread.current[@id].each do |args|
31
+ client.queue(*args)
32
+ end
33
+
34
+ client.commit
35
+ end
21
36
  end
22
37
  end
@@ -0,0 +1,45 @@
1
+ require_relative "prelude"
2
+
3
+ require "ohm"
4
+
5
+ class Post < Ohm::Model
6
+ attribute :title
7
+ end
8
+
9
+ setup do
10
+ Ohm.redis = Redic::Pool.new("redis://localhost:9999")
11
+ end
12
+
13
+ test "Pool - basic" do
14
+ threads = Array.new(10) do |i|
15
+ Thread.new(i) do |i|
16
+ 10.times do |j|
17
+ Post.create(title: "Foo #{i} #{j}").id
18
+ end
19
+ end
20
+ end
21
+
22
+ threads.each(&:join)
23
+
24
+ clients = Parsers.info(Ohm.redis.call("INFO", "clients")).fetch("connected_clients")
25
+
26
+ assert_equal(clients, "10")
27
+
28
+ teardown(Ohm.redis)
29
+
30
+ Ohm.redis = Redic::Pool.new("redis://localhost:9999")
31
+
32
+ threads = Array.new(10) do |i|
33
+ Thread.new(i) do |i|
34
+ 10.times do |j|
35
+ Post.all.to_a
36
+ end
37
+ end
38
+ end
39
+
40
+ threads.each(&:join)
41
+
42
+ clients = Parsers.info(Ohm.redis.call("INFO", "clients")).fetch("connected_clients")
43
+
44
+ assert_equal(clients, "10")
45
+ end
@@ -1,30 +1,4 @@
1
- require "cutest"
2
-
3
- $VERBOSE = 1
4
-
5
- module Parsers
6
- def self.info(reply)
7
- Hash[reply.lines.grep(/^[^#]/).map { |line| line.chomp.split(":", 2) }]
8
- end
9
- end
10
-
11
- require_relative "../lib/redic/pool"
12
-
13
- at_exit do
14
- if $redis
15
- Process.kill(:TERM, $redis)
16
- end
17
-
18
- Process.waitpid
19
- end
20
-
21
- $redis = spawn("redis-server --dir /tmp --dbfilename '' --port 9999 --logfile /dev/null")
22
-
23
- sleep(0.5)
24
-
25
- def teardown(r)
26
- r.pool.shutdown { |c| c.call("QUIT") }
27
- end
1
+ require_relative "prelude"
28
2
 
29
3
  setup do
30
4
  Redic::Pool.new("redis://localhost:9999", size: 10)
@@ -51,15 +25,13 @@ end
51
25
  test "MULTI return value with WATCH" do |r|
52
26
  r.call("DEL", "foo")
53
27
 
54
- r.with do |c|
55
- c.call("WATCH", "foo", "bar")
28
+ r.call("WATCH", "foo", "bar")
56
29
 
57
- c.queue("MULTI")
58
- c.queue("SET", "foo", "bar")
59
- c.queue("EXEC")
30
+ r.queue("MULTI")
31
+ r.queue("SET", "foo", "bar")
32
+ r.queue("EXEC")
60
33
 
61
- assert_equal(c.commit.last, ["OK"])
62
- end
34
+ assert_equal(r.commit.last, ["OK"])
63
35
 
64
36
  assert_equal(r.call("GET", "foo"), "bar")
65
37
 
@@ -69,47 +41,20 @@ end
69
41
  test "Pipelining" do |r|
70
42
  r.call("DEL", "foo")
71
43
 
72
- catch(:out) do
73
- r.with do |c|
74
- c.queue("SET", "foo", "bar")
75
- throw(:out)
76
- end
77
- end
44
+ r.queue("SET", "foo", "bar")
78
45
 
79
46
  assert_equal nil, r.call("GET", "foo")
80
47
 
81
48
  teardown(r)
82
49
  end
83
50
 
84
- test "Pipelining with nesting" do |r|
85
- r.call("DEL", "foo")
86
-
87
- r.with do |c1|
88
- c1.queue("DEL", "foo")
89
-
90
- r.with do |c2|
91
- c2.queue("SET", "foo", "bar")
92
- end
93
-
94
- c1.commit
95
- end
96
-
97
- assert_equal "bar", r.call("GET", "foo")
98
-
99
- teardown(r)
100
- end
101
-
102
51
  test "Pipelining contention" do |r|
103
52
  threads = Array.new(100) do
104
53
  Thread.new do
105
54
  10.times do
106
- r.with do |c|
107
- c.call("SET", "foo", "bar")
55
+ r.call("SET", "foo", "bar")
108
56
 
109
- r.with do |c|
110
- c.call("DEL", "foo")
111
- end
112
- end
57
+ r.call("DEL", "foo")
113
58
  end
114
59
  end
115
60
  end
@@ -117,11 +62,9 @@ test "Pipelining contention" do |r|
117
62
  threads += Array.new(100) do
118
63
  Thread.new do
119
64
  10.times do
120
- r.with do |c|
121
- c.queue("SET", "foo", "bar")
122
- c.queue("DEL", "foo")
123
- c.commit
124
- end
65
+ r.queue("SET", "foo", "bar")
66
+ r.queue("DEL", "foo")
67
+ r.commit
125
68
  end
126
69
  end
127
70
  end
@@ -135,3 +78,7 @@ test "Pipelining contention" do |r|
135
78
 
136
79
  teardown(r)
137
80
  end
81
+
82
+ test "URL" do |r|
83
+ assert_equal("redis://localhost:9999", r.url)
84
+ end
@@ -0,0 +1,27 @@
1
+ require "cutest"
2
+
3
+ $VERBOSE = 1
4
+
5
+ module Parsers
6
+ def self.info(reply)
7
+ Hash[reply.lines.grep(/^[^#]/).map { |line| line.chomp.split(":", 2) }]
8
+ end
9
+ end
10
+
11
+ require_relative "../lib/redic/pool"
12
+
13
+ at_exit do
14
+ if $redis
15
+ Process.kill(:TERM, $redis)
16
+ end
17
+
18
+ Process.waitpid
19
+ end
20
+
21
+ $redis = spawn("redis-server --dir /tmp --dbfilename '' --port 9999 --logfile /dev/null")
22
+
23
+ sleep(0.5)
24
+
25
+ def teardown(r)
26
+ r.pool.shutdown { |c| c.call("QUIT") }
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redic-pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -66,7 +66,9 @@ files:
66
66
  - lib/redic/pool.rb
67
67
  - rakefile
68
68
  - redic-pool.gemspec
69
+ - test/ohm_test.rb
69
70
  - test/pool_test.rb
71
+ - test/prelude.rb
70
72
  homepage: https://github.com/djanowski/redic-pool
71
73
  licenses:
72
74
  - Unlicense
@@ -92,4 +94,6 @@ signing_key:
92
94
  specification_version: 4
93
95
  summary: A Redis connection pool using Redic.
94
96
  test_files:
97
+ - test/ohm_test.rb
95
98
  - test/pool_test.rb
99
+ - test/prelude.rb