barrage 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 247efe0edfb9aae9c762b6698e5c90816c95f781
4
- data.tar.gz: 117e43352f37892a675334b48e2b398a90fe167b
2
+ SHA256:
3
+ metadata.gz: 9f4e3f94545667fc55e7efb109d64c1e87f6a382d8ec7ced5f4076c7813f1ea7
4
+ data.tar.gz: e4e99afca1bf2b0c234349db437dc42fa439199ebce178053e86c9b512dd68bb
5
5
  SHA512:
6
- metadata.gz: ef97bd700202ccdd92acb5a1c498d8ca1245fd6ac8a077acd8ce3f2f9e536de3f04989e77717128a956c30f5714f6c2947e3a3f115a19ec937a428d448ba16af
7
- data.tar.gz: 27265f705dfb1d087a441c86747f70496a505346751a7bbf24c14ff9e9357ec8a91a680a901ff446f3fff52716332f09760c9407c423906bfbf0202eb29aecf3
6
+ metadata.gz: 6a538c813035749f2732aa3f445d24636af10980f99ebb6e3072de8a59b2ca194cdd58123e8704e85f78dd62eedefe073717fc324c8e5dbe53352ac536da2cda
7
+ data.tar.gz: f91dd3eed5970c31b19c42c24739aa396c0766349d25c090a8ee378e7914d2f4cab2ebf20f973376af191212ed250e6c61b772d6731f4b707cc8907d9ed22e87
data/.travis.yml CHANGED
@@ -1,7 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.2
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.0
7
+ bundler_args: --jobs=2
5
8
  services:
6
9
  - redis-server
7
10
  script: bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ * Compatible with Redis 5.0
6
+
7
+ ## 0.1.1
8
+
9
+ * Fix redis client disconnect
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  * Fix RedisWorkerId's worker_id handling
data/Gemfile CHANGED
@@ -2,3 +2,17 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in barrage.gemspec
4
4
  gemspec
5
+
6
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2")
7
+ gem "activesupport", "< 5.0.0"
8
+ end
9
+
10
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.3")
11
+ gem "listen", "< 3.1.0"
12
+ end
13
+
14
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.5")
15
+ gem "ruby_dep", "< 1.4.0"
16
+ end
17
+
18
+ gem "redis", ">= 4.0.0"
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Barrage
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/barrage.svg)](http://badge.fury.io/rb/barrage)
4
+ [![Dependency Status](https://gemnasium.com/drecom/barrage.svg)](https://gemnasium.com/drecom/barrage)
4
5
  [![Coverage Status](https://img.shields.io/coveralls/drecom/barrage.svg)](https://coveralls.io/r/drecom/barrage)
6
+ [![Build Status](https://travis-ci.org/drecom/barrage.svg)](https://travis-ci.org/drecom/barrage)
7
+ [![Code Climate](https://codeclimate.com/github/drecom/barrage.png)](https://codeclimate.com/github/drecom/barrage)
5
8
 
6
9
  Distributed ID generator(like twitter/snowflake)
7
10
 
@@ -44,6 +47,8 @@ barrage.next
44
47
 
45
48
  #### msec
46
49
  #### redis_worker_id
50
+ requirement: redis 2.6+
51
+
47
52
  #### sequence
48
53
 
49
54
  ### Creating your own generator
data/barrage.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activesupport"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec", "~> 3.0.0"
25
+ spec.add_development_dependency "rspec"
26
26
  spec.add_development_dependency "rspec-its"
27
27
  spec.add_development_dependency "pry"
28
28
  spec.add_development_dependency "guard-rspec"
@@ -50,7 +50,20 @@ class Barrage
50
50
 
51
51
  if redis.is_a?(Redis) and redis.connected?
52
52
  redis.del("barrage:worker:#{worker_id}") if real_ttl > Time.now.to_i
53
- redis.client.disconnect
53
+
54
+ close_redis_connection(redis)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def close_redis_connection(redis)
61
+ redis_version = Gem.loaded_specs["redis"]&.version
62
+
63
+ if redis_version && redis_version >= Gem::Version.new("5.0.0")
64
+ redis._client.close
65
+ else
66
+ redis._client.disconnect
54
67
  end
55
68
  end
56
69
  end
@@ -63,7 +76,7 @@ class Barrage
63
76
  end
64
77
  new_worker_id = redis.evalsha(
65
78
  script_sha,
66
- argv: [2 ** length, rand(2 ** length), @worker_id, ttl, RACE_CONDITION_TTL]
79
+ argv: [2 ** length, rand(2 ** length), (@worker_id || 0), ttl, RACE_CONDITION_TTL]
67
80
  )
68
81
  new_worker_id or raise StandardError, "Renew redis worker id failed"
69
82
  return new_worker_id.to_i
@@ -1,3 +1,3 @@
1
1
  class Barrage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -30,7 +30,7 @@ describe Barrage::Generators::RedisWorkerId do
30
30
  it { is_expected.to be < 2 ** length }
31
31
 
32
32
  context "on many instances" do
33
- subject { 64.times.map { described_class.new(options) } }
33
+ subject { 3.times.map { described_class.new(options) } }
34
34
  let(:length) { 8 }
35
35
 
36
36
  it "should generate unique numbers" do
@@ -43,4 +43,38 @@ describe Barrage::Generators::RedisWorkerId do
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ describe "#Finalizer" do
48
+ subject { described_class::Finalizer.new(data).call(*args) }
49
+
50
+ let(:now) { Time.now.to_i }
51
+ let(:ttl) { 300 }
52
+ let(:redis) { Redis.new }
53
+ let(:worker_ttl) { now + ttl / 2 }
54
+ let(:real_ttl) { now + ttl }
55
+ let(:data) { [redis, worker_ttl, real_ttl] }
56
+ let(:args) { {} }
57
+
58
+ if Gem.loaded_specs["redis"]&.version >= Gem::Version.new("5.0.0")
59
+ before do
60
+ redis._client.send(:raw_connection)
61
+ end
62
+
63
+ it "redis client disconnect" do
64
+ subject
65
+
66
+ expect(redis.connected?).to be_nil
67
+ end
68
+ else
69
+ before do
70
+ redis._client.connect
71
+ end
72
+
73
+ it "redis client disconnect" do
74
+ subject
75
+
76
+ expect(redis.connected?).to eq false
77
+ end
78
+ end
79
+ end
46
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barrage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -199,7 +199,7 @@ homepage: http://github.com/drecom/barrage
199
199
  licenses:
200
200
  - MIT
201
201
  metadata: {}
202
- post_install_message:
202
+ post_install_message:
203
203
  rdoc_options: []
204
204
  require_paths:
205
205
  - lib
@@ -214,9 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubyforge_project:
218
- rubygems_version: 2.2.2
219
- signing_key:
217
+ rubygems_version: 3.3.3
218
+ signing_key:
220
219
  specification_version: 4
221
220
  summary: Distributed id generator
222
221
  test_files: