redis_getlock 0.1.0 → 0.1.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: 036e43b36aedd8b5350a4c6654a9e23bd67578cc
4
- data.tar.gz: b89cfca59c6fd6f9817741a60fcfdd839aa04d9d
3
+ metadata.gz: a5ec4a3361c80eb549bd10339f8238fcfff931ff
4
+ data.tar.gz: f014c8fed835373c21c8e97b8bf9c9248b6c7437
5
5
  SHA512:
6
- metadata.gz: 60e3c90c10505acfceb91f1f67cbcbec663d3ac3c1d967b9db62ce5cb7b3107367bcb3ba9d0e3c8fb74958f63a2042a096f96cdd095e59e89d809bac363f2071
7
- data.tar.gz: 0a2abe5631ae645f0f6c37612a6885616ba14d0fc4c893e5252dec7e9ffc3351746538558cfe511a816b8e886c3675ca7060facc93843af664ae1d321796bcf5
6
+ metadata.gz: 1d29834b4078ed4ba5badcb4019061cde85eb1583c54dddb5e8e8f8cdaec5541d4964875e1cf4ac666ce508fd200a5e5e548e44a34a7d7ccec75046676400df4
7
+ data.tar.gz: a13b4af68d49ebf0da7cf9721e4ee1e2ed843c05fe3d3c5346707ca431ad5e5cdb0e69ec48504f12faecdccd90a61ac211137e8328d34558c0edff50a5c15e63
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.1 (2016-02-28)
2
+
3
+ Changes:
4
+
5
+ * Trivial change of log format
6
+
1
7
  # 0.1.0 (2016-02-28)
2
8
 
3
9
  First version
10
+
data/README.md CHANGED
@@ -30,9 +30,9 @@ This gem takes a following approach to resolve this problem.
30
30
  1. Expiration time is set to `2` (default) seconds
31
31
  2. Extend the lock in each `1` (default) sencond interval invoking another thread
32
32
 
33
- This way ensures to release orphaned lock in 2 seconds.
33
+ This way ensures to release orphaned lock in 2 seconds. We are released from caring of the value of `timeout`!!
34
34
 
35
- Simple codes are as follows:
35
+ Simple ruby codes to explain how this gem works are as follows:
36
36
 
37
37
  ```ruby
38
38
  loop do
@@ -83,6 +83,19 @@ Similarly with ruby standard library [mutex](https://ruby-doc.org/core-2.2.0/Mut
83
83
  * unlock
84
84
  * Releases the lock.
85
85
 
86
+ Options of `RedisGetlock.new` are:
87
+
88
+ * redis
89
+ * Provide a redis instance
90
+ * key
91
+ * Key name for a distributed lock
92
+ * logger
93
+ * Provide a logger for RedisGetlock (for debug)
94
+ * timeout
95
+ * The expiration timeout of the lock. The default is `2` second. Users usually do not need to care of this because the expiration is automatically extended in a invoked thread.
96
+ * interval
97
+ * Interval to extend lock expiration. Must be `timeout > interval`. The default is `1` second.
98
+
86
99
  ### Example
87
100
 
88
101
  ```ruby
@@ -1,3 +1,3 @@
1
1
  class RedisGetlock
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/redis_getlock.rb CHANGED
@@ -17,7 +17,7 @@ class RedisGetlock
17
17
  end
18
18
 
19
19
  def lock
20
- logger.info { "RedisGetlock: Wait acquiring a lock: #{key}" } if logger
20
+ logger.info { "#{log_head}Wait acquiring a redis lock '#{key}'" } if logger
21
21
  if set_options_available?
22
22
  lock_with_set_options
23
23
  @thr = Thread.new(&method(:keeplock_with_set_options))
@@ -25,13 +25,13 @@ class RedisGetlock
25
25
  lock_without_set_options
26
26
  @thr = Thread.new(&method(:keeplock_without_set_options))
27
27
  end
28
- logger.info { "RedisGetlock: Acquired a lock: #{key}" } if logger
28
+ logger.info { "#{log_head}Acquired a redis lock '#{key}'" } if logger
29
29
  end
30
30
 
31
31
  def unlock
32
32
  @thr.terminate
33
33
  redis.del(key)
34
- logger.info { "RedisGetlock: Released a lock: #{key}" } if logger
34
+ logger.info { "#{log_head}Released a redis lock '#{key}'" } if logger
35
35
  end
36
36
 
37
37
  def locked?
@@ -49,6 +49,10 @@ class RedisGetlock
49
49
 
50
50
  private
51
51
 
52
+ def log_head
53
+ "PID-#{::Process.pid} TID-#{::Thread.current.object_id.to_s(36)}: "
54
+ end
55
+
52
56
  def set_options_available?
53
57
  return @set_options_avialble unless @set_options_avialble.nil?
54
58
  major, minor, patch = redis.info['redis_version'].split('.').map(&:to_i)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_getlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-27 00:00:00.000000000 Z
11
+ date: 2016-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis