ruby_redis_lock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.loadpath +5 -0
- data/.project +17 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +31 -0
- data/Readme.md +85 -0
- data/coverage/.resultset.json +240 -0
- data/coverage/assets/0.5.3/app.js +88 -0
- data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
- data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/coverage/assets/0.5.3/favicon_green.png +0 -0
- data/coverage/assets/0.5.3/favicon_red.png +0 -0
- data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
- data/coverage/assets/0.5.3/highlight.css +129 -0
- data/coverage/assets/0.5.3/highlight.pack.js +1 -0
- data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
- data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
- data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
- data/coverage/assets/0.5.3/jquery.url.js +174 -0
- data/coverage/assets/0.5.3/loading.gif +0 -0
- data/coverage/assets/0.5.3/magnify.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
- data/coverage/assets/0.5.3/stylesheet.css +383 -0
- data/coverage/index.html +1575 -0
- data/lib/ruby_redis_lock.rb +9 -0
- data/lib/ruby_redis_lock/ruby_redis_lock.rb +66 -0
- data/redis_test.bat +2 -0
- data/ruby_redis_lock.gemspec +21 -0
- data/ruby_redis_lock.rdb +1 -0
- data/spec/acquire_lock_spec.rb +44 -0
- data/spec/lock_spec.rb +73 -0
- data/spec/release_lock_spec.rb +22 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/try_acquire_lock_spec.rb +31 -0
- data/test.conf +1 -0
- metadata +112 -0
data/.loadpath
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>ruby_redis_lock</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.rubypeople.rdt.core.rubybuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/ezmobius/redis-rb.git
|
3
|
+
revision: fffaa14ba473a0e2a1303f82f22e83b6abe01c64
|
4
|
+
specs:
|
5
|
+
redis (2.2.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
multi_json (1.0.3)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
simplecov (0.5.3)
|
21
|
+
multi_json (~> 1.0.3)
|
22
|
+
simplecov-html (~> 0.5.3)
|
23
|
+
simplecov-html (0.5.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x86-mingw32
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
redis!
|
30
|
+
rspec
|
31
|
+
simplecov
|
data/Readme.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
Ruby-Redis-Lock - Distributed lock for Ruby (using Redis)
|
2
|
+
=======================================================
|
3
|
+
|
4
|
+
A distributed lock that utilizes Redis.
|
5
|
+
It also handles failures.
|
6
|
+
If a process acquires a lock for more than some period of time (default is 60 seconds),
|
7
|
+
the lock is automatically released.
|
8
|
+
|
9
|
+
Basically, it follows the algorithm explained here: http://redis.io/commands/setnx
|
10
|
+
|
11
|
+
Nevertheless, the algorithm on releasing a lock is improved. Please the comments in http://redis.io/commands/setnx
|
12
|
+
|
13
|
+
The example of using it:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
|
17
|
+
$redis = Redis.new
|
18
|
+
|
19
|
+
$redis.lock('some_name', 60, 10) do
|
20
|
+
|
21
|
+
#
|
22
|
+
# Do some tasks here
|
23
|
+
#
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
The API is below:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
lock(lock_name, processing_timeout=60, acquiring_timout=10)
|
33
|
+
```
|
34
|
+
|
35
|
+
You can change processing_timeout and acquiring_timeout.
|
36
|
+
|
37
|
+
The lock will be expired after it has been acquired for a period of time longer than processing_timeout (in seconds).
|
38
|
+
|
39
|
+
An error will be raised if the lock cannot be acquired within acquiring_timeout (in seconds).
|
40
|
+
|
41
|
+
Installation
|
42
|
+
------------------
|
43
|
+
|
44
|
+
You can install it directly by:
|
45
|
+
|
46
|
+
```sh
|
47
|
+
gem install ruby_redis_lock
|
48
|
+
```
|
49
|
+
|
50
|
+
or put it in your Gemfile:
|
51
|
+
|
52
|
+
```sh
|
53
|
+
gen 'ruby_redis_lock'
|
54
|
+
```
|
55
|
+
|
56
|
+
Help me
|
57
|
+
--------------
|
58
|
+
|
59
|
+
1. Clone the project
|
60
|
+
2. Install all dependencies with
|
61
|
+
|
62
|
+
```
|
63
|
+
bundle install
|
64
|
+
```
|
65
|
+
|
66
|
+
3. Start Redis and running all test cases
|
67
|
+
|
68
|
+
```
|
69
|
+
bundle exec rspec spec/*
|
70
|
+
```
|
71
|
+
|
72
|
+
4. Add a feature, if everything is ok
|
73
|
+
5. Write tests for the feature
|
74
|
+
6. Send me a pull request
|
75
|
+
|
76
|
+
|
77
|
+
Author
|
78
|
+
------------
|
79
|
+
Tanin Na Nakorn
|
80
|
+
|
81
|
+
|
82
|
+
Boring legal stuff
|
83
|
+
-------------------
|
84
|
+
|
85
|
+
You can do whatever you want with it
|
@@ -0,0 +1,240 @@
|
|
1
|
+
{
|
2
|
+
"RSpec": {
|
3
|
+
"coverage": {
|
4
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/lib/ruby_redis_lock.rb": [
|
5
|
+
1,
|
6
|
+
null,
|
7
|
+
1,
|
8
|
+
null,
|
9
|
+
null,
|
10
|
+
1,
|
11
|
+
1,
|
12
|
+
null,
|
13
|
+
null
|
14
|
+
],
|
15
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/lib/ruby_redis_lock/ruby_redis_lock.rb": [
|
16
|
+
1,
|
17
|
+
null,
|
18
|
+
null,
|
19
|
+
1,
|
20
|
+
7,
|
21
|
+
6,
|
22
|
+
null,
|
23
|
+
7,
|
24
|
+
null,
|
25
|
+
null,
|
26
|
+
null,
|
27
|
+
1,
|
28
|
+
1,
|
29
|
+
null,
|
30
|
+
17,
|
31
|
+
null,
|
32
|
+
17,
|
33
|
+
null,
|
34
|
+
43,
|
35
|
+
null,
|
36
|
+
43,
|
37
|
+
2,
|
38
|
+
null,
|
39
|
+
null,
|
40
|
+
null,
|
41
|
+
null,
|
42
|
+
15,
|
43
|
+
null,
|
44
|
+
null,
|
45
|
+
null,
|
46
|
+
1,
|
47
|
+
null,
|
48
|
+
63,
|
49
|
+
63,
|
50
|
+
null,
|
51
|
+
47,
|
52
|
+
47,
|
53
|
+
null,
|
54
|
+
3,
|
55
|
+
3,
|
56
|
+
null,
|
57
|
+
0,
|
58
|
+
null,
|
59
|
+
null,
|
60
|
+
null,
|
61
|
+
1,
|
62
|
+
null,
|
63
|
+
10,
|
64
|
+
10,
|
65
|
+
null,
|
66
|
+
8,
|
67
|
+
null,
|
68
|
+
8,
|
69
|
+
8,
|
70
|
+
8,
|
71
|
+
null,
|
72
|
+
null,
|
73
|
+
0,
|
74
|
+
null,
|
75
|
+
null,
|
76
|
+
1,
|
77
|
+
140,
|
78
|
+
null,
|
79
|
+
null,
|
80
|
+
null,
|
81
|
+
null
|
82
|
+
],
|
83
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/spec/lock_spec.rb": [
|
84
|
+
1,
|
85
|
+
null,
|
86
|
+
1,
|
87
|
+
null,
|
88
|
+
1,
|
89
|
+
null,
|
90
|
+
1,
|
91
|
+
null,
|
92
|
+
null,
|
93
|
+
null,
|
94
|
+
1,
|
95
|
+
null,
|
96
|
+
1,
|
97
|
+
null,
|
98
|
+
1,
|
99
|
+
1,
|
100
|
+
1,
|
101
|
+
1,
|
102
|
+
null,
|
103
|
+
null,
|
104
|
+
null,
|
105
|
+
1,
|
106
|
+
null,
|
107
|
+
1,
|
108
|
+
null,
|
109
|
+
1,
|
110
|
+
null,
|
111
|
+
null,
|
112
|
+
null,
|
113
|
+
1,
|
114
|
+
null,
|
115
|
+
1,
|
116
|
+
null,
|
117
|
+
1,
|
118
|
+
1,
|
119
|
+
null,
|
120
|
+
null,
|
121
|
+
1,
|
122
|
+
null,
|
123
|
+
1,
|
124
|
+
null,
|
125
|
+
1,
|
126
|
+
null,
|
127
|
+
null,
|
128
|
+
null,
|
129
|
+
1,
|
130
|
+
null,
|
131
|
+
1,
|
132
|
+
1,
|
133
|
+
1,
|
134
|
+
1,
|
135
|
+
null,
|
136
|
+
null,
|
137
|
+
null,
|
138
|
+
1,
|
139
|
+
2,
|
140
|
+
null,
|
141
|
+
null,
|
142
|
+
null,
|
143
|
+
1,
|
144
|
+
null,
|
145
|
+
1,
|
146
|
+
1,
|
147
|
+
1,
|
148
|
+
null,
|
149
|
+
null,
|
150
|
+
null,
|
151
|
+
null,
|
152
|
+
1,
|
153
|
+
null,
|
154
|
+
null,
|
155
|
+
null,
|
156
|
+
null
|
157
|
+
],
|
158
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/spec/release_lock_spec.rb": [
|
159
|
+
1,
|
160
|
+
null,
|
161
|
+
1,
|
162
|
+
null,
|
163
|
+
1,
|
164
|
+
null,
|
165
|
+
1,
|
166
|
+
null,
|
167
|
+
1,
|
168
|
+
null,
|
169
|
+
null,
|
170
|
+
null,
|
171
|
+
1,
|
172
|
+
null,
|
173
|
+
1,
|
174
|
+
null,
|
175
|
+
1,
|
176
|
+
1,
|
177
|
+
null,
|
178
|
+
null,
|
179
|
+
null,
|
180
|
+
null
|
181
|
+
],
|
182
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/spec/spec_helper.rb": [
|
183
|
+
null,
|
184
|
+
1,
|
185
|
+
1,
|
186
|
+
1,
|
187
|
+
null,
|
188
|
+
null,
|
189
|
+
1,
|
190
|
+
null,
|
191
|
+
1,
|
192
|
+
null,
|
193
|
+
1,
|
194
|
+
null,
|
195
|
+
1,
|
196
|
+
null,
|
197
|
+
1,
|
198
|
+
15,
|
199
|
+
15,
|
200
|
+
null,
|
201
|
+
null,
|
202
|
+
null
|
203
|
+
],
|
204
|
+
"C:/Users/Tanin/Documents/Ruby/ruby_redis_lock/spec/try_acquire_lock_spec.rb": [
|
205
|
+
1,
|
206
|
+
null,
|
207
|
+
1,
|
208
|
+
null,
|
209
|
+
1,
|
210
|
+
null,
|
211
|
+
1,
|
212
|
+
null,
|
213
|
+
null,
|
214
|
+
null,
|
215
|
+
1,
|
216
|
+
null,
|
217
|
+
1,
|
218
|
+
1,
|
219
|
+
null,
|
220
|
+
null,
|
221
|
+
null,
|
222
|
+
1,
|
223
|
+
null,
|
224
|
+
1,
|
225
|
+
null,
|
226
|
+
1,
|
227
|
+
1,
|
228
|
+
null,
|
229
|
+
null,
|
230
|
+
null,
|
231
|
+
1,
|
232
|
+
null,
|
233
|
+
null,
|
234
|
+
null,
|
235
|
+
null
|
236
|
+
]
|
237
|
+
},
|
238
|
+
"timestamp": 1317324230
|
239
|
+
}
|
240
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
// Configuration for fancy sortable tables for source file groups
|
3
|
+
$('.file_list').dataTable({
|
4
|
+
"aaSorting": [[ 1, "asc" ]],
|
5
|
+
"bPaginate": false,
|
6
|
+
"bJQueryUI": true,
|
7
|
+
"aoColumns": [
|
8
|
+
null,
|
9
|
+
{ "sType": "percent" },
|
10
|
+
null,
|
11
|
+
null,
|
12
|
+
null,
|
13
|
+
null,
|
14
|
+
null
|
15
|
+
]
|
16
|
+
});
|
17
|
+
|
18
|
+
// Syntax highlight all files up front - deactivated
|
19
|
+
// $('.source_table pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
|
20
|
+
|
21
|
+
// Syntax highlight source files on first toggle of the file view popup
|
22
|
+
$("a.src_link").click(function() {
|
23
|
+
// Get the source file element that corresponds to the clicked element
|
24
|
+
var source_table = $($(this).attr('href'));
|
25
|
+
|
26
|
+
// If not highlighted yet, do it!
|
27
|
+
if (!source_table.hasClass('highlighted')) {
|
28
|
+
source_table.find('pre code').each(function(i, e) {hljs.highlightBlock(e, ' ')});
|
29
|
+
source_table.addClass('highlighted');
|
30
|
+
};
|
31
|
+
});
|
32
|
+
|
33
|
+
// Set-up of popup for source file views
|
34
|
+
$("a.src_link").fancybox({
|
35
|
+
'hideOnContentClick': true,
|
36
|
+
'centerOnScroll': true,
|
37
|
+
'width': '90%',
|
38
|
+
'padding': 0,
|
39
|
+
'transitionIn': 'elastic'
|
40
|
+
});
|
41
|
+
|
42
|
+
// Hide src files and file list container after load
|
43
|
+
$('.source_files').hide();
|
44
|
+
$('.file_list_container').hide();
|
45
|
+
|
46
|
+
// Add tabs based upon existing file_list_containers
|
47
|
+
$('.file_list_container h2').each(function(){
|
48
|
+
var container_id = $(this).parent().attr('id');
|
49
|
+
var group_name = $(this).find('.group_name').first().html();
|
50
|
+
var covered_percent = $(this).find('.covered_percent').first().html();
|
51
|
+
|
52
|
+
$('.group_tabs').append('<li><a href="#' + container_id + '">' + group_name + ' ('+ covered_percent +')</a></li>');
|
53
|
+
});
|
54
|
+
|
55
|
+
$('.group_tabs a').each( function() {
|
56
|
+
$(this).addClass($(this).attr('href').replace('#', ''));
|
57
|
+
});
|
58
|
+
|
59
|
+
// Make sure tabs don't get ugly focus borders when active
|
60
|
+
$('.group_tabs a').live('focus', function() { $(this).blur(); });
|
61
|
+
|
62
|
+
var favicon_path = $('link[rel="shortcut icon"]').attr('href');
|
63
|
+
$('.group_tabs a').live('click', function(){
|
64
|
+
if (!$(this).parent().hasClass('active')) {
|
65
|
+
$('.group_tabs a').parent().removeClass('active');
|
66
|
+
$(this).parent().addClass('active');
|
67
|
+
$('.file_list_container').hide();
|
68
|
+
$(".file_list_container" + $(this).attr('href')).show();
|
69
|
+
window.location.href = window.location.href.split('#')[0] + $(this).attr('href').replace('#', '#_');
|
70
|
+
|
71
|
+
// Force favicon reload - otherwise the location change containing anchor would drop the favicon...
|
72
|
+
// Works only on firefox, but still... - Anyone know a better solution to force favicon on local file?
|
73
|
+
$('link[rel="shortcut icon"]').remove();
|
74
|
+
$('head').append('<link rel="shortcut icon" type="image/png" href="'+ favicon_path +'" />');
|
75
|
+
};
|
76
|
+
return false;
|
77
|
+
});
|
78
|
+
|
79
|
+
if (jQuery.url.attr('anchor')) {
|
80
|
+
$('.group_tabs a.'+jQuery.url.attr('anchor').replace('_', '')).click();
|
81
|
+
} else {
|
82
|
+
$('.group_tabs a:first').click();
|
83
|
+
};
|
84
|
+
|
85
|
+
$("abbr.timeago").timeago();
|
86
|
+
$('#loading').fadeOut();
|
87
|
+
$('#wrapper').show();
|
88
|
+
});
|