barrage 0.1.1 → 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
2
  SHA256:
3
- metadata.gz: 1f1e0b5da1bcf39c6afcd692da7a90d3784bd791a83d2553c62b23c522de5e71
4
- data.tar.gz: 97c3f16796ab212ad5421d758fdf2773f040befde8170cf5682fa1607b84c84f
3
+ metadata.gz: 9f4e3f94545667fc55e7efb109d64c1e87f6a382d8ec7ced5f4076c7813f1ea7
4
+ data.tar.gz: e4e99afca1bf2b0c234349db437dc42fa439199ebce178053e86c9b512dd68bb
5
5
  SHA512:
6
- metadata.gz: 8c0189dfdd3286230938d122dee87d56d7d41fdf2526115ba87f34c1bbe3ed276e37efe485e8cb8f18dad253bc0b9452f0997db08e5400c5ad690a42da267fe8
7
- data.tar.gz: 2dff301124982ccec6670d36b53e1e2c48e9108c37eb80a559f85e6a371eccf89a682fcd5ff22485d23fbde51e9529914491f10cc5cf05b20244ecdb042c8e7f
6
+ metadata.gz: 6a538c813035749f2732aa3f445d24636af10980f99ebb6e3072de8a59b2ca194cdd58123e8704e85f78dd62eedefe073717fc324c8e5dbe53352ac536da2cda
7
+ data.tar.gz: f91dd3eed5970c31b19c42c24739aa396c0766349d25c090a8ee378e7914d2f4cab2ebf20f973376af191212ed250e6c61b772d6731f4b707cc8907d9ed22e87
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ * Compatible with Redis 5.0
6
+
3
7
  ## 0.1.1
4
8
 
5
9
  * Fix redis client disconnect
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.5.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,6 +50,19 @@ 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
+
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
53
66
  redis._client.disconnect
54
67
  end
55
68
  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.1"
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
@@ -47,9 +47,6 @@ describe Barrage::Generators::RedisWorkerId do
47
47
  describe "#Finalizer" do
48
48
  subject { described_class::Finalizer.new(data).call(*args) }
49
49
 
50
- before do
51
- redis._client.connect
52
- end
53
50
  let(:now) { Time.now.to_i }
54
51
  let(:ttl) { 300 }
55
52
  let(:redis) { Redis.new }
@@ -58,9 +55,26 @@ describe Barrage::Generators::RedisWorkerId do
58
55
  let(:data) { [redis, worker_ttl, real_ttl] }
59
56
  let(:args) { {} }
60
57
 
61
- it "redis client disconnect" do
62
- subject
63
- expect(redis.connected?).to eq false
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
64
78
  end
65
79
  end
66
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.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-24 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.5.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.5.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.0.3
217
+ rubygems_version: 3.3.3
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Distributed id generator