redlock 0.2.0 → 0.2.1

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: 3820d9812a87989c395ff8b4856a4cea7801d84b
4
- data.tar.gz: 7cc006346948cf1132be55de820949f37cb9f07d
3
+ metadata.gz: 8e34b717846f5f8faa005ab9a8d5cac3c3ea865e
4
+ data.tar.gz: f7a615768b2fc2746d16128122a69259c252b78f
5
5
  SHA512:
6
- metadata.gz: ba94bdcbdd4f659a6564baad82a3f022ea64f541789579803f33bfd0981ee6a3df53b6887a05791f3794202c85748ae85bdd357d1703d690464e6f0844b3e899
7
- data.tar.gz: c36ec9b01716486eeacdd9a82f27cbaa8d6b3165da1e17e11196ac4d700dfe82acf439e6b027b8852f5f33241af08927fea6c2d2f379ffca8392b1ac69a69c1d
6
+ metadata.gz: ced9a5040b0fe2b0d2ea947732495c06a647b8df04cb5cda89b3f82731d76f79446afda7dd86d21b6705c67f6ccfc42f5c44fa16b753d09abd242d590172fe63
7
+ data.tar.gz: 0ce3c67e5f9b81d2f8381daf9708c728f8ceaa6a3367e3153586c4621748ffcef717595333b184e7da08932be7e023dfab549b78040d064b079d762a173e800b
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redlock (0.2.0)
5
- redis (~> 3, >= 3.0.0)
4
+ redlock (0.2.1)
5
+ redis (>= 3.0.0, < 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  docile (1.1.5)
18
18
  json (2.0.3)
19
19
  rake (11.3.0)
20
- redis (3.3.3)
20
+ redis (4.0.1)
21
21
  rspec (3.5.0)
22
22
  rspec-core (~> 3.5.0)
23
23
  rspec-expectations (~> 3.5.0)
@@ -51,4 +51,4 @@ DEPENDENCIES
51
51
  rspec (~> 3, >= 3.0.0)
52
52
 
53
53
  BUNDLED WITH
54
- 1.12.5
54
+ 1.16.0
@@ -0,0 +1,4 @@
1
+ default: test
2
+ test:
3
+ docker-compose run --rm test
4
+
data/README.md CHANGED
@@ -129,22 +129,22 @@ It's possible to customize the retry logic providing the following options:
129
129
  retry_count: 3,
130
130
  retry_delay: 200, # milliseconds
131
131
  retry_jitter: 50, # milliseconds
132
- retry_timeout: 0.1 # seconds
132
+ redis_timeout: 0.1 # seconds
133
133
  })
134
134
  ```
135
135
 
136
- For more information you can check [documentation](https://github.com/leandromoreira/redlock-rb/blob/master/lib/redlock/client.rb#L13-L20)
136
+ For more information you can check [documentation](http://www.rubydoc.info/gems/redlock/Redlock%2FClient:initialize).
137
137
 
138
138
 
139
139
  ## Run tests
140
140
 
141
- Make sure you have at least 1 redis instances up.
141
+ Make sure you have [docker installed](https://docs.docker.com/engine/installation/).
142
142
 
143
- $ rspec
143
+ $ make
144
144
 
145
145
  ## Disclaimer
146
146
 
147
- This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments. You can see discussion about this approach at [reddit](http://www.reddit.com/r/programming/comments/2nt0nq/distributed_lock_using_redis_implemented_in_ruby/).
147
+ This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments. You can see discussion about this approach at [reddit](http://www.reddit.com/r/programming/comments/2nt0nq/distributed_lock_using_redis_implemented_in_ruby/) and also the [Antirez answers](http://antirez.com/news/101) for some critics.
148
148
 
149
149
  ## Contributing
150
150
 
@@ -0,0 +1,26 @@
1
+ EXITED=$(docker ps -q -f status=exited)
2
+ DANGLING=$(docker images -q -f "dangling=true")
3
+ DANGLING_VOLUME=$(docker volume ls -qf "dangling=true")
4
+
5
+ if [ "$1" == "--dry-run" ]; then
6
+ echo "==> Would stop containers:"
7
+ echo $EXITED
8
+ echo "==> And images:"
9
+ echo $DANGLING
10
+ else
11
+ if [ -n "$EXITED" ]; then
12
+ docker rm $EXITED
13
+ else
14
+ echo "No containers to remove."
15
+ fi
16
+ if [ -n "$DANGLING" ]; then
17
+ docker rmi $DANGLING
18
+ else
19
+ echo "No images to remove."
20
+ fi
21
+ if [ -n "$DANGLING_VOLUME" ]; then
22
+ docker volume rm $DANGLING_VOLUME
23
+ else
24
+ echo "No volumes to remove."
25
+ fi
26
+ fi
@@ -0,0 +1,27 @@
1
+ version: '2'
2
+ services:
3
+ test:
4
+ image: ruby
5
+ volumes:
6
+ - .:/redlock
7
+ working_dir: /redlock
8
+ command: bash -c "bundle install && rspec"
9
+ environment:
10
+ - REDIS1_HOST=redis1.local.com
11
+ - REDIS1_PORT=6379
12
+ - REDIS2_HOST=redis2.local.com
13
+ - REDIS2_PORT=6379
14
+ - DEFAULT_REDIS_HOST=redis1.local.com
15
+ - DEFAULT_REDIS_PORT=6379
16
+ links:
17
+ - redis1:redis1.local.com
18
+ - redis2:redis2.local.com
19
+ depends_on:
20
+ - redis1
21
+ - redis2
22
+
23
+ redis1:
24
+ image: redis
25
+ redis2:
26
+ image: redis
27
+
@@ -3,7 +3,9 @@ require 'securerandom'
3
3
 
4
4
  module Redlock
5
5
  class Client
6
- DEFAULT_REDIS_URLS = ['redis://localhost:6379']
6
+ DEFAULT_REDIS_HOST = ENV["DEFAULT_REDIS_HOST"] || "localhost"
7
+ DEFAULT_REDIS_PORT = ENV["DEFAULT_REDIS_PORT"] || "6379"
8
+ DEFAULT_REDIS_URLS = ["redis://#{DEFAULT_REDIS_HOST}:#{DEFAULT_REDIS_PORT}"]
7
9
  DEFAULT_REDIS_TIMEOUT = 0.1
8
10
  DEFAULT_RETRY_COUNT = 3
9
11
  DEFAULT_RETRY_DELAY = 200
@@ -27,7 +29,7 @@ module Redlock
27
29
  RedisInstance.new(server)
28
30
  end
29
31
  end
30
- @quorum = servers.length / 2 + 1
32
+ @quorum = (servers.length / 2).to_i + 1
31
33
  @retry_count = options[:retry_count] || DEFAULT_RETRY_COUNT
32
34
  @retry_delay = options[:retry_delay] || DEFAULT_RETRY_DELAY
33
35
  @retry_jitter = options[:retry_jitter] || DEFAULT_RETRY_JITTER
@@ -1,3 +1,3 @@
1
1
  module Redlock
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -18,7 +18,7 @@ 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 'redis', '~> 3', '>= 3.0.0'
21
+ spec.add_dependency 'redis', '>= 3.0.0', '< 5.0'
22
22
 
23
23
  spec.add_development_dependency "coveralls", "~> 0.8.13"
24
24
  spec.add_development_dependency 'rake', '~> 11.1', '>= 11.1.2'
@@ -7,17 +7,22 @@ RSpec.describe Redlock::Client do
7
7
  let(:lock_manager) { Redlock::Client.new(Redlock::Client::DEFAULT_REDIS_URLS, lock_manager_opts) }
8
8
  let(:resource_key) { SecureRandom.hex(3) }
9
9
  let(:ttl) { 1000 }
10
+ let(:redis1_host) { ENV["REDIS1_HOST"] || "localhost" }
11
+ let(:redis1_port) { ENV["REDIS1_PORT"] || "6379" }
12
+ let(:redis2_host) { ENV["REDIS2_HOST"] || "127.0.0.1" }
13
+ let(:redis2_port) { ENV["REDIS2_PORT"] || "6379" }
10
14
 
11
15
  describe 'initialize' do
12
16
  it 'accepts both redis URLs and Redis objects' do
13
- servers = [ 'redis://localhost:6379', Redis.new(url: 'redis://127.0.0.1:6379') ]
17
+ print redis1_host
18
+ servers = [ "redis://#{redis1_host}:#{redis1_port}", Redis.new(url: "redis://#{redis2_host}:#{redis2_port}") ]
14
19
  redlock = Redlock::Client.new(servers)
15
20
 
16
21
  redlock_servers = redlock.instance_variable_get(:@servers).map do |s|
17
- s.instance_variable_get(:@redis).client.host
22
+ s.instance_variable_get(:@redis).connection[:host]
18
23
  end
19
24
 
20
- expect(redlock_servers).to match_array(%w{ localhost 127.0.0.1 })
25
+ expect(redlock_servers).to match_array([redis1_host, redis2_host])
21
26
  end
22
27
  end
23
28
 
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Moreira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 3.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '3'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 3.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: coveralls
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -98,8 +98,11 @@ files:
98
98
  - Gemfile
99
99
  - Gemfile.lock
100
100
  - LICENSE
101
+ - Makefile
101
102
  - README.md
102
103
  - Rakefile
104
+ - clean_docker.sh
105
+ - docker-compose.yml
103
106
  - lib/redlock.rb
104
107
  - lib/redlock/client.rb
105
108
  - lib/redlock/testing.rb
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
131
  version: '0'
129
132
  requirements: []
130
133
  rubyforge_project:
131
- rubygems_version: 2.4.5
134
+ rubygems_version: 2.5.1
132
135
  signing_key:
133
136
  specification_version: 4
134
137
  summary: Distributed lock using Redis written in Ruby.