redis-lock 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ log/*
2
+ redis-lock*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis-lock.gemspec
4
+ gemspec
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redis-lock (0.0.1)
5
+ redis
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ redis (3.0.5)
12
+ rspec (2.14.1)
13
+ rspec-core (~> 2.14.0)
14
+ rspec-expectations (~> 2.14.0)
15
+ rspec-mocks (~> 2.14.0)
16
+ rspec-core (2.14.6)
17
+ rspec-expectations (2.14.3)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.14.4)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ redis-lock!
26
+ rspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Patrick Tulskie
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,53 +1 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "redis-lock"
8
- gem.summary = %Q{TODO: one-line summary of your gem}
9
- gem.description = %Q{TODO: longer description of your gem}
10
- gem.email = "patricktulskie@gmail.com"
11
- gem.homepage = "http://github.com/PatrickTulskie/redis-lock"
12
- gem.authors = ["Patrick Tulskie"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "redis-lock #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
1
+ require "bundler/gem_tasks"
@@ -2,4 +2,6 @@ require File.dirname(__FILE__) + '/../lib/redis/lock'
2
2
 
3
3
  class Redis
4
4
  include Redis::Lock
5
- end
5
+ end
6
+
7
+ class RedisLockException < Exception; end
@@ -0,0 +1,5 @@
1
+ module Redis
2
+ module Lock
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -14,8 +14,12 @@ class Redis
14
14
 
15
15
  def lock_for_update(key, timeout = 60, max_attempts = 100)
16
16
  if self.lock(key, timeout, max_attempts)
17
- response = yield if block_given?
18
- self.unlock(key)
17
+ response = nil
18
+ begin
19
+ response = yield if block_given?
20
+ ensure
21
+ self.unlock(key)
22
+ end
19
23
  return response
20
24
  end
21
25
  end
@@ -41,7 +45,7 @@ class Redis
41
45
  end
42
46
  end
43
47
 
44
- raise "Unable to acquire lock for #{key}."
48
+ raise RedisLockException.new("Unable to acquire lock for #{key}.")
45
49
  rescue => e
46
50
  if e.message == "Unable to acquire lock for #{key}."
47
51
  if attempt_counter == max_attempts
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis-lock/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "redis-lock"
8
+ gem.version = Redis::Lock::VERSION
9
+ gem.authors = ["Patrick Tulskie"]
10
+ gem.email = ["patricktulskie@gmail.com"]
11
+ gem.description = %q{Pessimistic locking for ruby redis}
12
+ gem.summary = %q{Pessimistic locking for ruby redis}
13
+ gem.homepage = "https://github.com/PatrickTulskie/redis-lock"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "redis"
21
+ gem.add_development_dependency "rspec"
22
+ end
metadata CHANGED
@@ -1,87 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redis-lock
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Patrick Tulskie
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-01-16 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: redis
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: " Adds pessimistic locking capabilities to the redis gem.\n \n Since these capabilities are utilized client-side, all clients must use this gem and follow the order of lock => make changes => unlock in order to obtain maximum safety when modifying sensitive keys.\n \n Tested with redis-server 2.0.4 and should work with all versions > 0.091.\n"
36
- email: patricktulskie@gmail.com
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Pessimistic locking for ruby redis
47
+ email:
48
+ - patricktulskie@gmail.com
37
49
  executables: []
38
-
39
50
  extensions: []
40
-
41
- extra_rdoc_files:
42
- - README.md
43
- files:
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE.txt
44
57
  - README.md
45
58
  - Rakefile
46
- - VERSION
47
59
  - lib/redis-lock.rb
60
+ - lib/redis-lock/version.rb
48
61
  - lib/redis/lock.rb
62
+ - redis-lock.gemspec
49
63
  - spec/redis_spec.rb
50
64
  - spec/spec_helper.rb
51
- has_rdoc: true
52
- homepage: http://github.com/PatrickTulskie/redis-lock
65
+ homepage: https://github.com/PatrickTulskie/redis-lock
53
66
  licenses: []
54
-
55
67
  post_install_message:
56
- rdoc_options:
57
- - --charset=UTF-8
58
- require_paths:
68
+ rdoc_options: []
69
+ require_paths:
59
70
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ required_ruby_version: !ruby/object:Gem::Requirement
61
72
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
78
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
78
83
  requirements: []
79
-
80
84
  rubyforge_project:
81
- rubygems_version: 1.4.1
85
+ rubygems_version: 1.8.24
82
86
  signing_key:
83
87
  specification_version: 3
84
- summary: Adds the ability to utilize client-side pessimistic locking in Redis.
85
- test_files:
88
+ summary: Pessimistic locking for ruby redis
89
+ test_files:
86
90
  - spec/redis_spec.rb
87
91
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0