redis-mutex 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +2 -8
- data/{LICENSE.txt → LICENSE} +4 -2
- data/README.md +2 -0
- data/Rakefile +10 -31
- data/lib/redis/mutex/version.rb +5 -0
- data/lib/redis/mutex.rb +5 -0
- data/lib/redis-mutex.rb +1 -4
- data/redis-mutex.gemspec +20 -56
- data/spec/redis_mutex_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -7
- metadata +35 -27
- data/.document +0 -5
- data/Gemfile.lock +0 -32
- data/VERSION +0 -1
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/{LICENSE.txt → LICENSE}
RENAMED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2012 Kenn Ejima
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Redis Mutex
|
2
2
|
===========
|
3
3
|
|
4
|
+
[](http://travis-ci.org/kenn/redis-mutex)
|
5
|
+
|
4
6
|
Distrubuted mutex in Ruby using Redis. Supports both **blocking** and **non-blocking** semantics.
|
5
7
|
|
6
8
|
The idea was taken from [the official SETNX doc](http://redis.io/commands/setnx).
|
data/Rakefile
CHANGED
@@ -1,35 +1,14 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake/file_utils'
|
11
|
-
include FileUtils
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
12
3
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = "Distrubuted mutex using Redis"
|
19
|
-
gem.description = "Distrubuted mutex using Redis"
|
20
|
-
gem.email = "kenn.ejima@gmail.com"
|
21
|
-
gem.authors = ["Kenn Ejima"]
|
22
|
-
end
|
23
|
-
Jeweler::RubygemsDotOrgTasks.new
|
4
|
+
# RSpec
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new('spec')
|
7
|
+
task :default => :spec
|
24
8
|
|
25
|
-
|
9
|
+
# Custom Tasks
|
10
|
+
desc 'Flush the test database'
|
26
11
|
task :flushdb do
|
27
|
-
require 'redis
|
28
|
-
Redis
|
29
|
-
Redis::Classy.flushdb
|
30
|
-
end
|
31
|
-
|
32
|
-
task :default => :spec
|
33
|
-
task :spec do
|
34
|
-
exec "rspec spec"
|
12
|
+
require 'redis'
|
13
|
+
Redis.new(:db => 15).flushdb
|
35
14
|
end
|
data/lib/redis/mutex.rb
CHANGED
@@ -11,6 +11,8 @@ class Redis
|
|
11
11
|
#
|
12
12
|
class Mutex < Redis::Classy
|
13
13
|
autoload :Macro, 'redis/mutex/macro'
|
14
|
+
autoload :VERSION, 'redis/mutex/version'
|
15
|
+
|
14
16
|
attr_reader :locking
|
15
17
|
DEFAULT_EXPIRE = 10
|
16
18
|
|
@@ -68,6 +70,9 @@ class Redis
|
|
68
70
|
end
|
69
71
|
|
70
72
|
class << self
|
73
|
+
def to_ary
|
74
|
+
|
75
|
+
end
|
71
76
|
def sweep
|
72
77
|
return 0 if (all_keys = self.keys).empty?
|
73
78
|
|
data/lib/redis-mutex.rb
CHANGED
data/redis-mutex.gemspec
CHANGED
@@ -1,62 +1,26 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# WARNING: do not directly load redis/mutex/version so avoid superclass mismatch. load from the top instead.
|
3
|
+
require File.expand_path('../lib/redis-mutex', __FILE__)
|
5
4
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["Kenn Ejima"]
|
7
|
+
gem.email = ["kenn.ejima@gmail.com"]
|
8
|
+
gem.description = %q{Distrubuted mutex using Redis}
|
9
|
+
gem.summary = %q{Distrubuted mutex using Redis}
|
10
|
+
gem.homepage = "http://github.com/kenn/redis-mutex"
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".rspec",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"README.md",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"lib/redis-mutex.rb",
|
29
|
-
"lib/redis/mutex.rb",
|
30
|
-
"lib/redis/mutex/macro.rb",
|
31
|
-
"redis-mutex.gemspec",
|
32
|
-
"spec/redis_mutex_spec.rb",
|
33
|
-
"spec/spec_helper.rb"
|
34
|
-
]
|
35
|
-
s.homepage = "http://github.com/kenn/redis-mutex"
|
36
|
-
s.licenses = ["MIT"]
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = "1.8.11"
|
39
|
-
s.summary = "Distrubuted mutex using Redis"
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "redis-mutex"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Redis::Mutex::VERSION
|
40
18
|
|
41
|
-
|
42
|
-
|
19
|
+
gem.add_runtime_dependency "redis-classy", "~> 1.0"
|
20
|
+
gem.add_runtime_dependency "redis"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "bundler"
|
43
23
|
|
44
|
-
|
45
|
-
|
46
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
47
|
-
s.add_development_dependency(%q<bundler>, [">= 0"])
|
48
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<redis-classy>, ["~> 1.0.0"])
|
51
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
53
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
54
|
-
end
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<redis-classy>, ["~> 1.0.0"])
|
57
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
58
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
59
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
60
|
-
end
|
24
|
+
# For Travis
|
25
|
+
gem.add_development_dependency "rake"
|
61
26
|
end
|
62
|
-
|
data/spec/redis_mutex_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe Redis::Mutex do
|
|
45
45
|
|
46
46
|
it "should not remove the key if lock is held past expiration" do
|
47
47
|
mutex = Redis::Mutex.new(:test_lock, :expire => 0.1, :block => 0)
|
48
|
-
mutex.lock
|
48
|
+
mutex.lock.should be_true
|
49
49
|
sleep 0.2 # lock expired
|
50
50
|
|
51
51
|
# someone overwrites the expired lock
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
3
4
|
require 'rspec'
|
4
5
|
require 'redis-mutex'
|
5
6
|
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
10
7
|
RSpec.configure do |config|
|
11
8
|
# Use database 15 for testing so we don't accidentally step on you real data.
|
12
|
-
Redis::Classy.db = Redis.new(:db => 15)
|
9
|
+
Redis::Classy.db = Redis::Mutex.db = Redis.new(:db => 15)
|
13
10
|
unless Redis::Classy.keys.empty?
|
14
11
|
puts '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
|
15
12
|
exit!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-mutex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis-classy
|
16
|
-
requirement: &
|
16
|
+
requirement: &70134892192360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.0
|
21
|
+
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70134892192360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redis
|
27
|
+
requirement: &70134892190980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70134892190980
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70134892206020 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70134892206020
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: bundler
|
38
|
-
requirement: &
|
49
|
+
requirement: &70134892205000 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70134892205000
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement: &
|
59
|
+
name: rake
|
60
|
+
requirement: &70134892203600 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,32 +65,30 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70134892203600
|
58
69
|
description: Distrubuted mutex using Redis
|
59
|
-
email:
|
70
|
+
email:
|
71
|
+
- kenn.ejima@gmail.com
|
60
72
|
executables: []
|
61
73
|
extensions: []
|
62
|
-
extra_rdoc_files:
|
63
|
-
- LICENSE.txt
|
64
|
-
- README.md
|
74
|
+
extra_rdoc_files: []
|
65
75
|
files:
|
66
|
-
- .
|
76
|
+
- .gitignore
|
67
77
|
- .rspec
|
78
|
+
- .travis.yml
|
68
79
|
- Gemfile
|
69
|
-
-
|
70
|
-
- LICENSE.txt
|
80
|
+
- LICENSE
|
71
81
|
- README.md
|
72
82
|
- Rakefile
|
73
|
-
- VERSION
|
74
83
|
- lib/redis-mutex.rb
|
75
84
|
- lib/redis/mutex.rb
|
76
85
|
- lib/redis/mutex/macro.rb
|
86
|
+
- lib/redis/mutex/version.rb
|
77
87
|
- redis-mutex.gemspec
|
78
88
|
- spec/redis_mutex_spec.rb
|
79
89
|
- spec/spec_helper.rb
|
80
90
|
homepage: http://github.com/kenn/redis-mutex
|
81
|
-
licenses:
|
82
|
-
- MIT
|
91
|
+
licenses: []
|
83
92
|
post_install_message:
|
84
93
|
rdoc_options: []
|
85
94
|
require_paths:
|
@@ -90,9 +99,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
99
|
- - ! '>='
|
91
100
|
- !ruby/object:Gem::Version
|
92
101
|
version: '0'
|
93
|
-
segments:
|
94
|
-
- 0
|
95
|
-
hash: 2435582858684301188
|
96
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
103
|
none: false
|
98
104
|
requirements:
|
@@ -101,8 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
107
|
version: '0'
|
102
108
|
requirements: []
|
103
109
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
110
|
+
rubygems_version: 1.8.17
|
105
111
|
signing_key:
|
106
112
|
specification_version: 3
|
107
113
|
summary: Distrubuted mutex using Redis
|
108
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- spec/redis_mutex_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
data/.document
DELETED
data/Gemfile.lock
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
diff-lcs (1.1.3)
|
5
|
-
git (1.2.5)
|
6
|
-
jeweler (1.6.4)
|
7
|
-
bundler (~> 1.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
rake (0.9.2.2)
|
11
|
-
redis (2.2.2)
|
12
|
-
redis-classy (1.0.1)
|
13
|
-
redis-namespace (~> 1.0)
|
14
|
-
redis-namespace (1.1.0)
|
15
|
-
redis (< 3.0.0)
|
16
|
-
rspec (2.7.0)
|
17
|
-
rspec-core (~> 2.7.0)
|
18
|
-
rspec-expectations (~> 2.7.0)
|
19
|
-
rspec-mocks (~> 2.7.0)
|
20
|
-
rspec-core (2.7.1)
|
21
|
-
rspec-expectations (2.7.0)
|
22
|
-
diff-lcs (~> 1.1.2)
|
23
|
-
rspec-mocks (2.7.0)
|
24
|
-
|
25
|
-
PLATFORMS
|
26
|
-
ruby
|
27
|
-
|
28
|
-
DEPENDENCIES
|
29
|
-
bundler
|
30
|
-
jeweler
|
31
|
-
redis-classy (~> 1.0.0)
|
32
|
-
rspec
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.2.3
|