redis-pool 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +10 -0
- data/lib/redis/pool.rb +10 -15
- data/test/pool_test.rb +45 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGI4Mjc4YzE0OTcwYzNhNGIzMWNmYzI2MWQxOWIxYTllOGMzMTMzOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTM0NjlmZWM0MjdmNGVmMTBjYWMxM2Y1NWQyOWFiOTRlMmRjODBkMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGNmMTllOGE4YzA5MDQxN2QzNWNiZGYyNmU0MjRiMGM4MDZiOTQxOGQ2ZDI4
|
10
|
+
NWMxYzgyYjg1NTY1NTMzZWQ0ZmFlNWUyMWUzYzQ1Mzc2ZTdhZGJmMWY3YzVl
|
11
|
+
ODBkOTc2NThjYTA1MWUwMTA3MGQ2NDI1Zjg1YWNjODc4MzJmZjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmFhNzY4YzhmMGM0ZGFhZDJkYThlMmRjZDA3OWE2ZWRjYTM5OGUyOTc1NTEz
|
14
|
+
MTRkNTE2OTNhYWY0MmMxOGIzZGQ3ZTI2YjMzYWFiODE1ZGQ3NzE2YmU2ZTY4
|
15
|
+
MTExMTU3Njc0NmJhYmY4NGFjZjNkZjNmZGE1NTJjMzE0Yzg4ZjY=
|
data/CHANGELOG.md
ADDED
data/lib/redis/pool.rb
CHANGED
@@ -2,7 +2,7 @@ require "connection_pool"
|
|
2
2
|
require "redis"
|
3
3
|
|
4
4
|
class Redis::Pool < Redis
|
5
|
-
VERSION = "0.1.
|
5
|
+
VERSION = "0.1.1"
|
6
6
|
|
7
7
|
attr :pool
|
8
8
|
|
@@ -14,8 +14,12 @@ class Redis::Pool < Redis
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def synchronize
|
17
|
-
|
18
|
-
|
17
|
+
if current = Thread.current[@id]
|
18
|
+
yield(current)
|
19
|
+
else
|
20
|
+
@pool.with do |client|
|
21
|
+
_with_client(client) { yield(client) }
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
@@ -33,24 +37,15 @@ class Redis::Pool < Redis
|
|
33
37
|
|
34
38
|
def multi
|
35
39
|
raise ArgumentError, "Redis::Pool#multi can only be called with a block" unless block_given?
|
36
|
-
|
37
|
-
pipeline = Pipeline::Multi.new
|
38
|
-
|
39
|
-
_with_client(pipeline) do |client|
|
40
|
-
yield(client)
|
41
|
-
end
|
42
|
-
|
43
|
-
synchronize do |client|
|
44
|
-
client.call_pipeline(pipeline)
|
45
|
-
end
|
40
|
+
super
|
46
41
|
end
|
47
42
|
|
48
43
|
protected
|
49
44
|
|
50
45
|
def _with_client(client)
|
51
|
-
Thread.current[@id] = client
|
46
|
+
old, Thread.current[@id] = Thread.current[@id], client
|
52
47
|
yield(client)
|
53
48
|
ensure
|
54
|
-
Thread.current[@id] =
|
49
|
+
Thread.current[@id] = old
|
55
50
|
end
|
56
51
|
end
|
data/test/pool_test.rb
CHANGED
@@ -38,7 +38,52 @@ test "Pool" do |r|
|
|
38
38
|
teardown(r)
|
39
39
|
end
|
40
40
|
|
41
|
+
test "MULTI return value with WATCH" do |r|
|
42
|
+
r.del("foo")
|
43
|
+
|
44
|
+
r.pool.with do
|
45
|
+
r.watch("foo", "bar")
|
46
|
+
|
47
|
+
assert r.multi { r.set("foo", "bar") }
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal r.get("foo"), "bar"
|
51
|
+
|
52
|
+
teardown(r)
|
53
|
+
end
|
54
|
+
|
41
55
|
test "Pipelining" do |r|
|
56
|
+
r.del("foo")
|
57
|
+
|
58
|
+
catch(:out) do
|
59
|
+
r.pipelined do
|
60
|
+
r.set("foo", "bar")
|
61
|
+
throw(:out)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
assert_equal r.get("foo"), nil
|
66
|
+
|
67
|
+
teardown(r)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "Pipelining with nesting" do |r|
|
71
|
+
r.del("foo")
|
72
|
+
|
73
|
+
r.pipelined do
|
74
|
+
r.del("foo")
|
75
|
+
|
76
|
+
r.pipelined do
|
77
|
+
r.set("foo", "bar")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_equal r.get("foo"), "bar"
|
82
|
+
|
83
|
+
teardown(r)
|
84
|
+
end
|
85
|
+
|
86
|
+
test "Pipelining contention" do |r|
|
42
87
|
threads = Array.new(100) do
|
43
88
|
Thread.new do
|
44
89
|
10.times do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-08-
|
11
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- CHANGELOG.md
|
63
64
|
- README.md
|
64
65
|
- UNLICENSE
|
65
66
|
- lib/redis/pool.rb
|