redis_ha 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -1
- data/lib/redis_ha/connection.rb +17 -3
- data/redis_ha.gemspec +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -5,6 +5,30 @@ Three basic CRDTs (set, hashmap and counter) for redis. Also includes
|
|
5
5
|
a ConnectionPool that allows you to run concurrent redis commands on
|
6
6
|
multiple connections w/o using eventmachine/em-hiredis.
|
7
7
|
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
Create a RedisHA::ConnectionPool
|
12
|
+
|
13
|
+
here be dragons
|
14
|
+
|
15
|
+
|
16
|
+
ADD/REM/GET on a RedisHA::Set
|
17
|
+
|
18
|
+
here be dragons
|
19
|
+
|
20
|
+
|
21
|
+
INCR/DECR/SET/GET on a RedisHA::Counter
|
22
|
+
|
23
|
+
here be dragons
|
24
|
+
|
25
|
+
|
26
|
+
SET/GET on a RedisHA::HashMap
|
27
|
+
|
28
|
+
here be dragons
|
29
|
+
|
30
|
+
|
31
|
+
|
8
32
|
|
9
33
|
Installation
|
10
34
|
------------
|
@@ -13,7 +37,7 @@ Installation
|
|
13
37
|
|
14
38
|
or in your Gemfile:
|
15
39
|
|
16
|
-
gem 'redis_ha', '~> 0.
|
40
|
+
gem 'redis_ha', '~> 0.3'
|
17
41
|
|
18
42
|
|
19
43
|
License
|
data/lib/redis_ha/connection.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class RedisHA::Connection < Thread
|
2
2
|
|
3
|
+
POLL_INTERVAL = 0.00001
|
4
|
+
|
3
5
|
attr_accessor :status, :buffer
|
4
6
|
|
5
7
|
def initialize(redis_opts, opts = {})
|
@@ -9,7 +11,7 @@ class RedisHA::Connection < Thread
|
|
9
11
|
@retry_timeout = opts[:retry_timeout]
|
10
12
|
@redis_opts = redis_opts
|
11
13
|
|
12
|
-
@queue =
|
14
|
+
@queue = Array.new
|
13
15
|
@buffer = Array.new
|
14
16
|
@lock = Mutex.new
|
15
17
|
|
@@ -25,13 +27,15 @@ class RedisHA::Connection < Thread
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def <<(msg)
|
28
|
-
@
|
30
|
+
@lock.synchronize do
|
31
|
+
@queue << msg
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
private
|
32
36
|
|
33
37
|
def run
|
34
|
-
while job =
|
38
|
+
while job = pop
|
35
39
|
semaphore, *msg = job
|
36
40
|
|
37
41
|
@lock.synchronize do
|
@@ -42,6 +46,16 @@ private
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
def pop
|
50
|
+
loop do
|
51
|
+
sleep(POLL_INTERVAL) while @queue.size < 1
|
52
|
+
@lock.synchronize do
|
53
|
+
job = @queue.shift
|
54
|
+
return job if job
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
def connect
|
46
60
|
with_timeout_and_check do
|
47
61
|
@redis = Redis.new(@redis_opts)
|
data/redis_ha.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_ha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &13405180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.2.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13405180
|
25
25
|
description: Three basic CRDTs (set, hashmap and counter) for redis. Also includes
|
26
26
|
a ConnectionPool that allows you to run concurrent redis commands on multiple connections
|
27
27
|
w/o using eventmachine/em-hiredis.
|