mysql_getlock 0.1.2 → 0.2.0

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: 5a8480ec312241e0c2b54f02aa4de40fe991e148
4
- data.tar.gz: 6e3311e683eeb0906e43ea1e6bd520c13d01835a
3
+ metadata.gz: 13472db42b56d8508600971446847ed1eca62d47
4
+ data.tar.gz: 3f29aaa3f8507db4ad7a4c5bb2785ee961cb5a49
5
5
  SHA512:
6
- metadata.gz: 2ae6e6631468a268861051a4258959c12e6db7fe16f98eb3f21af023923240804988ef762ba955e3889c719a3bd3ece47c108ce87f8ae061c7682f57dc39a70e
7
- data.tar.gz: 8c40374163c91c2ca1f93d57018b99c6bf58388f16b353e65f4594c04eced43d14c3166d98411f56a135ba30059e339de6318e954816cf2439ad2c1e1f2efa22
6
+ metadata.gz: 55970b8a826d111753244739c70c5ab97b5f12135e9813a78089ebc756a05eafb649e2d400b57ddbf650ba8d0f1188364d916807f9633c0d4641d7d1c1ed8c8a
7
+ data.tar.gz: c2cf83488fa66076b885a966e73eaba7c893a53ffe47283e81b21d9773a7ee0180bb69f5fe9d590e3c6339e5136b8e5fbfc5ea01acd4d117976281f5632b7e26
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.2.0 (2016-08-28)
2
+
3
+ Enhancements:
4
+
5
+ * Add #self_locked? to check lock is obtained by myself
6
+
1
7
  # 0.1.2 (2016-08-28)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -24,7 +24,8 @@ MySQL `get_lock()` has a characteristic that the lock is implicitly released whe
24
24
 
25
25
  Note that
26
26
 
27
- 1. Before 5.7.5, only a single simultaneous lock can be acquired in a session, and `GET_LOCK()` releases any existing lock. This gem raises `MysqlGetlock::Error` on such situation.
27
+ 1. Before 5.7.5, only a single simultaneous lock can be acquired in a session, and `get_lock()` releases any existing lock.
28
+ * This gem raises `MysqlGetlock::Error` at `#lock` if another `get_lock()` for another key is issued in a session to prevent accidental releases of existing lock.
28
29
  2. The key name is global in a mysql instance. It is advised to use database-specific or application-specific lock names such as `db_name.str` or `app_name.environment.str`
29
30
 
30
31
  ## Installation
@@ -50,11 +51,13 @@ Similarly with ruby standard library [mutex](https://ruby-doc.org/core-2.2.0/Mut
50
51
  * lock
51
52
  * Attempts to grab the lock and waits if it isn’t availabl. Returns true if successfully acquird a lock.
52
53
  * locked?
53
- * Returns true if this lock is currently held by some.
54
+ * Returns true if this lock is currently held by some (including myself)
54
55
  * synchronize {}
55
56
  * Obtains a lock, runs the block, and releases the lock when the block completes.
56
57
  * unlock
57
58
  * Releases the lock. Returns true if successfully released a lock.
59
+ * self_locked?
60
+ * Returns true if this lock is currently held by myself.
58
61
 
59
62
  Options of `MysqlGetlock.new` are:
60
63
 
data/lib/mysql_getlock.rb CHANGED
@@ -66,8 +66,18 @@ class MysqlGetlock
66
66
  end
67
67
 
68
68
  def locked?
69
- results = mysql2.query(%Q[select is_free_lock('#{key}')], as: :array)
70
- results.to_a.first.first == 0
69
+ results = mysql2.query(%Q[select is_used_lock('#{key}')], as: :array)
70
+ !!results.to_a.first.first
71
+ end
72
+
73
+ # return true if locked by myself
74
+ def self_locked?
75
+ results = mysql2.query(%Q[select is_used_lock('#{key}')], as: :array)
76
+ lock_id = results.to_a.first.first
77
+ return nil if lock_id.nil?
78
+ results = mysql2.query(%Q[select connection_id()], as: :array)
79
+ self_id = results.to_a.first.first
80
+ self_id == lock_id
71
81
  end
72
82
 
73
83
  def synchronize(&block)
@@ -1,3 +1,3 @@
1
1
  class MysqlGetlock
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_getlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo