restruct 0.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b08da180cd16bfdb19e965f58ed2f6bdc0590558
4
- data.tar.gz: 5eb60adcfa2585711ae48a8b26718d062c0fad8d
3
+ metadata.gz: 2bd75f82dde2f17f7b562be3a8fe5b264028eaba
4
+ data.tar.gz: ed15597cbf0b1487d4ab9697649dd3575ff01e75
5
5
  SHA512:
6
- metadata.gz: 15795162d1328da9f16764494398379e87004db5e9491672d60ebe94d99d17ba5ac8f7eaf83648f3a62b31aa34caa2c70350abbb730790131bb1ff54e1832b0e
7
- data.tar.gz: 1bf098b79cdc7b020abf55849fe5a9fe399e0c6a43c9e0bc9efd65523df97ecf3d923610e756925632e8cf6a416588faf1d816669fbce95f8977592bcf7256a1
6
+ metadata.gz: f5febc64be1599503c84a16a66a1e3fd0d447c99db365f620d67043117a3f49a92f6aeb37b75e11e3df1b8ccd75059d076f2aebfd61c4052eaa0b429a8c34b53
7
+ data.tar.gz: 22c7f357f209ee553c05699a1f3e252b65da9378596c1002da42a161ab2b29504215bbf6818d25547160fe0dc38794bba2e48bf0f3d9bac0b5e3a60ce3323cfe
@@ -1 +1 @@
1
- ruby 2.0
1
+ ruby-2.3.0
@@ -5,6 +5,7 @@ rvm:
5
5
  - 2.1
6
6
  - 2.2
7
7
  - 2.3.0
8
+ - 2.4.0
8
9
  - jruby
9
10
  before_install:
10
11
  - gem install bundler
data/README.md CHANGED
@@ -14,7 +14,6 @@ Redis structures
14
14
  - NestedHash
15
15
  - Queue
16
16
  - Locker
17
- - Channel
18
17
 
19
18
  ## Installation
20
19
 
@@ -1,4 +1,5 @@
1
1
  require 'redic'
2
+ require 'redic-sentinels'
2
3
  require 'class_config'
3
4
  require 'forwardable'
4
5
  require 'securerandom'
@@ -11,14 +12,12 @@ require_relative 'restruct/array'
11
12
  require_relative 'restruct/set'
12
13
  require_relative 'restruct/hash'
13
14
  require_relative 'restruct/queue'
14
- require_relative 'restruct/channel'
15
15
  require_relative 'restruct/nested_hash'
16
16
  require_relative 'restruct/marshalizable'
17
17
  require_relative 'restruct/marshal_array'
18
18
  require_relative 'restruct/marshal_set'
19
19
  require_relative 'restruct/marshal_hash'
20
20
  require_relative 'restruct/marshal_queue'
21
- require_relative 'restruct/marshal_channel'
22
21
  require_relative 'restruct/locker'
23
22
  require_relative 'restruct/connection'
24
23
 
@@ -27,7 +26,7 @@ module Restruct
27
26
 
28
27
  extend ClassConfig
29
28
 
30
- attr_config :connection, Connection.new
29
+ attr_config :connection, Connection.simple
31
30
  attr_config :id_separator, ':'
32
31
  attr_config :id_generator, ->() { Id.new(:restruct)[SecureRandom.uuid] }
33
32
 
@@ -1,9 +1,23 @@
1
1
  module Restruct
2
+
2
3
  class Connection
3
4
 
4
- def initialize(*args)
5
- @args = args
6
- @redis = Redic.new *args
5
+ class << self
6
+
7
+ def simple(*args)
8
+ new Redic.new(*args)
9
+ end
10
+
11
+ def with_sentinels(*args)
12
+ new Redic::Sentinels.new(*args)
13
+ end
14
+
15
+ private :new
16
+
17
+ end
18
+
19
+ def initialize(redis=nil)
20
+ @redis = redis || Redic.new
7
21
  @scripts = {}
8
22
  @nesting = ::Hash.new { |h,k| h[k] = 0 }
9
23
  end
@@ -45,14 +59,6 @@ module Restruct
45
59
  raise ex
46
60
  end
47
61
 
48
- def read
49
- redis.client.read
50
- end
51
-
52
- def clone
53
- Connection.new *@args
54
- end
55
-
56
62
  private
57
63
 
58
64
  attr_reader :redis, :scripts
@@ -29,7 +29,7 @@ module Restruct
29
29
  private
30
30
 
31
31
  def _lock(key, exclusive)
32
- connection.script REGISTER_LUA, 0, id, key, exclusive
32
+ connection.script REGISTER_LUA, 0, id, key, exclusive
33
33
  begin
34
34
  yield
35
35
  ensure
@@ -1,3 +1,3 @@
1
1
  module Restruct
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'redic', '~> 1.5.0'
22
- spec.add_dependency 'class_config', '~> 0.0.1'
21
+ spec.add_dependency 'redic', '~> 1.5'
22
+ spec.add_dependency 'redic-sentinels', '~> 0.1'
23
+ spec.add_dependency 'class_config', '~> 0.0'
23
24
 
24
25
  spec.add_development_dependency 'bundler', '~> 1.12'
25
26
  spec.add_development_dependency 'rake', '~> 11.0'
@@ -85,7 +85,7 @@ describe Restruct::Locker do
85
85
 
86
86
  pids = 10.times.map do |thread_number|
87
87
  Process.fork do
88
- connection = Restruct::Connection.new
88
+ connection = Restruct::Connection.simple
89
89
  locker = Restruct::Locker.new id: locker_id, connection: connection
90
90
  10.times do |iteration|
91
91
  locker.lock :process_1 do
metadata CHANGED
@@ -1,167 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-05 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.0
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redic-sentinels
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: class_config
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 0.0.1
47
+ version: '0.0'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ~>
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 0.0.1
54
+ version: '0.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
61
  version: '1.12'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.12'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '11.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ~>
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '11.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: minitest
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ~>
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
89
  version: '5.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ~>
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '5.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: minitest-great_expectations
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - '>='
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: minitest-colorin
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ~>
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0.1'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ~>
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0.1'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: minitest-line
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ~>
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0.6'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ~>
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.6'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ~>
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0.12'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ~>
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0.12'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: coveralls
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ~>
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0.8'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ~>
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0.8'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: pry-nav
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ~>
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
173
  version: '0.2'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ~>
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0.2'
167
181
  description: Redis structures
@@ -171,25 +185,23 @@ executables: []
171
185
  extensions: []
172
186
  extra_rdoc_files: []
173
187
  files:
174
- - .coveralls.yml
175
- - .gitignore
176
- - .ruby-gemset
177
- - .ruby-version
178
- - .travis.yml
188
+ - ".coveralls.yml"
189
+ - ".gitignore"
190
+ - ".ruby-gemset"
191
+ - ".ruby-version"
192
+ - ".travis.yml"
179
193
  - Gemfile
180
194
  - LICENSE.txt
181
195
  - README.md
182
196
  - Rakefile
183
197
  - lib/restruct.rb
184
198
  - lib/restruct/array.rb
185
- - lib/restruct/channel.rb
186
199
  - lib/restruct/connection.rb
187
200
  - lib/restruct/errors.rb
188
201
  - lib/restruct/hash.rb
189
202
  - lib/restruct/id.rb
190
203
  - lib/restruct/locker.rb
191
204
  - lib/restruct/marshal_array.rb
192
- - lib/restruct/marshal_channel.rb
193
205
  - lib/restruct/marshal_hash.rb
194
206
  - lib/restruct/marshal_queue.rb
195
207
  - lib/restruct/marshal_set.rb
@@ -203,7 +215,6 @@ files:
203
215
  - lua/unregister.lua
204
216
  - restruct.gemspec
205
217
  - spec/array_spec.rb
206
- - spec/channel_spec.rb
207
218
  - spec/connection_spec.rb
208
219
  - spec/coverage_helper.rb
209
220
  - spec/hash_spec.rb
@@ -223,23 +234,22 @@ require_paths:
223
234
  - lib
224
235
  required_ruby_version: !ruby/object:Gem::Requirement
225
236
  requirements:
226
- - - '>='
237
+ - - ">="
227
238
  - !ruby/object:Gem::Version
228
239
  version: '0'
229
240
  required_rubygems_version: !ruby/object:Gem::Requirement
230
241
  requirements:
231
- - - '>='
242
+ - - ">="
232
243
  - !ruby/object:Gem::Version
233
244
  version: '0'
234
245
  requirements: []
235
246
  rubyforge_project:
236
- rubygems_version: 2.4.8
247
+ rubygems_version: 2.5.1
237
248
  signing_key:
238
249
  specification_version: 4
239
250
  summary: Redis structures
240
251
  test_files:
241
252
  - spec/array_spec.rb
242
- - spec/channel_spec.rb
243
253
  - spec/connection_spec.rb
244
254
  - spec/coverage_helper.rb
245
255
  - spec/hash_spec.rb
@@ -1,31 +0,0 @@
1
- module Restruct
2
- class Channel < Structure
3
-
4
- def publish(message)
5
- connection.call 'PUBLISH', id, serialize(message)
6
- end
7
-
8
- def subscribe
9
- subscriber = connection.clone
10
- subscriber.call 'SUBSCRIBE', id
11
- loop do
12
- yield deserialize(subscriber.read.last)
13
- end
14
- rescue => ex
15
- raise ex
16
- ensure
17
- subscriber.call 'UNSUBSCRIBE', id
18
- end
19
-
20
- private
21
-
22
- def serialize(string)
23
- string
24
- end
25
-
26
- def deserialize(string)
27
- string
28
- end
29
-
30
- end
31
- end
@@ -1,5 +0,0 @@
1
- module Restruct
2
- class MarshalChannel < Channel
3
- include Marshalizable
4
- end
5
- end
@@ -1,33 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- [Restruct::Channel, Restruct::MarshalChannel].each do |klass|
4
-
5
- describe klass do
6
-
7
- let(:channel) { klass.new }
8
-
9
- it 'Subscribe and publish' do
10
- messages = []
11
-
12
- Thread.new do
13
- channel.subscribe do |message|
14
- messages << message
15
- end
16
- end
17
- sleep 0.01 # Wait for establish connection
18
-
19
- 3.times do |i|
20
- channel.publish "Message #{i}"
21
- end
22
-
23
- Timeout.timeout(3) do
24
- while messages.count < 3;
25
- sleep 0.0001 # Wait for subscriptions
26
- end
27
- end
28
-
29
- messages.must_equal 3.times.map { |i| "Message #{i}" }
30
- end
31
-
32
- end
33
- end