redis_support 0.0.16 → 0.0.17
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/lib/redis_support/locks.rb +14 -1
- data/test/test_redis_support.rb +18 -3
- metadata +6 -6
data/lib/redis_support/locks.rb
CHANGED
@@ -16,6 +16,19 @@ module RedisSupport
|
|
16
16
|
release_redis_lock( key_to_lock )
|
17
17
|
end
|
18
18
|
|
19
|
+
# Attempt to lock a block of code so it can only be accessed by one
|
20
|
+
# thread in our system at a time. Skips the block if it cannot lock.
|
21
|
+
#
|
22
|
+
# See 'acquire_redis_lock_nonblock' for details on parameters.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def redis_lock_nonblock( key_to_lock, expiration = 30 )
|
26
|
+
lock_acquired = acquire_redis_lock_nonblock( key_to_lock, expiration )
|
27
|
+
yield if lock_acquired
|
28
|
+
ensure
|
29
|
+
release_redis_lock( key_to_lock ) if lock_acquired
|
30
|
+
end
|
31
|
+
|
19
32
|
# Throttle a block of code so it is only executed at most every
|
20
33
|
# `expiration` seconds. The block is skipped if it has been run
|
21
34
|
# more recently.
|
@@ -112,7 +125,7 @@ module RedisSupport
|
|
112
125
|
#
|
113
126
|
# Returns the timestamp.
|
114
127
|
def timeout_i( timeout )
|
115
|
-
|
128
|
+
Time.now.to_i + timeout.to_i
|
116
129
|
end
|
117
130
|
end
|
118
131
|
end
|
data/test/test_redis_support.rb
CHANGED
@@ -108,9 +108,24 @@ context "Redis Support" do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
test "registered keys should show up in keystruct" do
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
["test:redis", "test:redis:VAR", "test:redis:VAR_ONE:VAR_TWO:append"].each do |key|
|
112
|
+
assert TestClass::Keys.keystructs.include?(key)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test "redis_lock_nonblock performs as expected" do
|
117
|
+
class Zoo
|
118
|
+
include RedisSupport
|
119
|
+
end
|
120
|
+
|
121
|
+
Zoo.redis_lock_nonblock("example:key") do
|
122
|
+
assert Zoo.has_redis_lock?("example:key")
|
123
|
+
Zoo.redis_lock_nonblock("example:key") do
|
124
|
+
assert(false, 'Second nonblocking lock should not have been acquired')
|
125
|
+
end
|
126
|
+
assert Zoo.has_redis_lock?("example:key")
|
127
|
+
end
|
128
|
+
assert !Zoo.has_redis_lock?("example:key")
|
114
129
|
end
|
115
130
|
end
|
116
131
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 61
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 17
|
10
|
+
version: 0.0.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian P O'Rourke
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-01
|
19
|
+
date: 2011-12-01 00:00:00 -08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements: []
|
95
95
|
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 1.3.7
|
98
98
|
signing_key:
|
99
99
|
specification_version: 3
|
100
100
|
summary: A Redis Support module
|