redis_queued_locks 1.0.0 → 1.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/README.md +84 -17
- data/lib/redis_queued_locks/acquier/acquire_lock/delay_execution.rb +2 -2
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb +4 -4
- data/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb +2 -2
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_with_expire.rb +4 -4
- data/lib/redis_queued_locks/acquier/acquire_lock.rb +9 -9
- data/lib/redis_queued_locks/acquier/clear_dead_requests.rb +3 -3
- data/lib/redis_queued_locks/acquier/extend_lock_ttl.rb +3 -3
- data/lib/redis_queued_locks/acquier/is_locked.rb +2 -2
- data/lib/redis_queued_locks/acquier/is_queued.rb +2 -2
- data/lib/redis_queued_locks/acquier/keys.rb +2 -2
- data/lib/redis_queued_locks/acquier/lock_info.rb +2 -2
- data/lib/redis_queued_locks/acquier/locks.rb +4 -4
- data/lib/redis_queued_locks/acquier/queue_info.rb +2 -2
- data/lib/redis_queued_locks/acquier/queues.rb +4 -4
- data/lib/redis_queued_locks/acquier/release_all_locks.rb +4 -4
- data/lib/redis_queued_locks/acquier/release_lock.rb +4 -4
- data/lib/redis_queued_locks/acquier.rb +1 -1
- data/lib/redis_queued_locks/client.rb +27 -25
- data/lib/redis_queued_locks/debugger/interface.rb +4 -4
- data/lib/redis_queued_locks/debugger.rb +8 -8
- data/lib/redis_queued_locks/errors.rb +6 -6
- data/lib/redis_queued_locks/instrument/active_support.rb +2 -2
- data/lib/redis_queued_locks/instrument/void_notifier.rb +2 -2
- data/lib/redis_queued_locks/instrument.rb +2 -2
- data/lib/redis_queued_locks/logging/void_logger.rb +10 -10
- data/lib/redis_queued_locks/logging.rb +10 -3
- data/lib/redis_queued_locks/resource.rb +16 -16
- data/lib/redis_queued_locks/utilities.rb +2 -2
- data/lib/redis_queued_locks/version.rb +2 -2
- data/lib/redis_queued_locks.rb +2 -2
- metadata +3 -3
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
# rubocop:disable Metrics/ClassLength
|
6
6
|
class RedisQueuedLocks::Client
|
7
|
-
# @since
|
7
|
+
# @since 1.0.0
|
8
8
|
include Qonfig::Configurable
|
9
9
|
|
10
10
|
configuration do
|
@@ -41,7 +41,7 @@ class RedisQueuedLocks::Client
|
|
41
41
|
# @return [RedisClient]
|
42
42
|
#
|
43
43
|
# @api private
|
44
|
-
# @since
|
44
|
+
# @since 1.0.0
|
45
45
|
attr_reader :redis_client
|
46
46
|
|
47
47
|
# NOTE: attr_access here is chosen intentionally in order to have an ability to change
|
@@ -49,7 +49,7 @@ class RedisQueuedLocks::Client
|
|
49
49
|
# @return [String]
|
50
50
|
#
|
51
51
|
# @api private
|
52
|
-
# @since
|
52
|
+
# @since 1.0.0
|
53
53
|
attr_accessor :uniq_identity
|
54
54
|
|
55
55
|
# @param redis_client [RedisClient]
|
@@ -60,7 +60,7 @@ class RedisQueuedLocks::Client
|
|
60
60
|
# @return [void]
|
61
61
|
#
|
62
62
|
# @api public
|
63
|
-
# @since
|
63
|
+
# @since 1.0.0
|
64
64
|
def initialize(redis_client, &configs)
|
65
65
|
configure(&configs)
|
66
66
|
@uniq_identity = config[:uniq_identifier].call
|
@@ -116,7 +116,7 @@ class RedisQueuedLocks::Client
|
|
116
116
|
# - If block is given the result of block's yeld will be returned.
|
117
117
|
#
|
118
118
|
# @api public
|
119
|
-
# @since
|
119
|
+
# @since 1.0.0
|
120
120
|
def lock(
|
121
121
|
lock_name,
|
122
122
|
ttl: config[:default_lock_ttl],
|
@@ -164,7 +164,7 @@ class RedisQueuedLocks::Client
|
|
164
164
|
# @note See #lock method signature.
|
165
165
|
#
|
166
166
|
# @api public
|
167
|
-
# @since
|
167
|
+
# @since 1.0.0
|
168
168
|
def lock!(
|
169
169
|
lock_name,
|
170
170
|
ttl: config[:default_lock_ttl],
|
@@ -219,7 +219,7 @@ class RedisQueuedLocks::Client
|
|
219
219
|
# }
|
220
220
|
#
|
221
221
|
# @api public
|
222
|
-
# @since
|
222
|
+
# @since 1.0.0
|
223
223
|
def unlock(
|
224
224
|
lock_name,
|
225
225
|
logger: config[:logger],
|
@@ -238,7 +238,7 @@ class RedisQueuedLocks::Client
|
|
238
238
|
# @return [Boolean]
|
239
239
|
#
|
240
240
|
# @api public
|
241
|
-
# @since
|
241
|
+
# @since 1.0.0
|
242
242
|
def locked?(lock_name)
|
243
243
|
RedisQueuedLocks::Acquier::IsLocked.locked?(redis_client, lock_name)
|
244
244
|
end
|
@@ -247,7 +247,7 @@ class RedisQueuedLocks::Client
|
|
247
247
|
# @return [Boolean]
|
248
248
|
#
|
249
249
|
# @api public
|
250
|
-
# @since
|
250
|
+
# @since 1.0.0
|
251
251
|
def queued?(lock_name)
|
252
252
|
RedisQueuedLocks::Acquier::IsQueued.queued?(redis_client, lock_name)
|
253
253
|
end
|
@@ -256,7 +256,7 @@ class RedisQueuedLocks::Client
|
|
256
256
|
# @return [Hash<String,String|Numeric>,NilClass]
|
257
257
|
#
|
258
258
|
# @api public
|
259
|
-
# @since
|
259
|
+
# @since 1.0.0
|
260
260
|
def lock_info(lock_name)
|
261
261
|
RedisQueuedLocks::Acquier::LockInfo.lock_info(redis_client, lock_name)
|
262
262
|
end
|
@@ -265,7 +265,7 @@ class RedisQueuedLocks::Client
|
|
265
265
|
# @return [Hash<String|Array<Hash<String,String|Numeric>>,NilClass]
|
266
266
|
#
|
267
267
|
# @api public
|
268
|
-
# @since
|
268
|
+
# @since 1.0.0
|
269
269
|
def queue_info(lock_name)
|
270
270
|
RedisQueuedLocks::Acquier::QueueInfo.queue_info(redis_client, lock_name)
|
271
271
|
end
|
@@ -288,7 +288,7 @@ class RedisQueuedLocks::Client
|
|
288
288
|
# - { ok: false, result: :async_expire_or_no_lock }
|
289
289
|
#
|
290
290
|
# @api public
|
291
|
-
# @since
|
291
|
+
# @since 1.0.0
|
292
292
|
def extend_lock_ttl(lock_name, milliseconds, logger: config[:logger])
|
293
293
|
RedisQueuedLocks::Acquier::ExtendLockTTL.extend_lock_ttl(
|
294
294
|
redis_client,
|
@@ -311,7 +311,7 @@ class RedisQueuedLocks::Client
|
|
311
311
|
# Example: { ok: true, result { rel_key_cnt: 100, rel_time: 0.01 } }
|
312
312
|
#
|
313
313
|
# @api public
|
314
|
-
# @since
|
314
|
+
# @since 1.0.0
|
315
315
|
def clear_locks(
|
316
316
|
batch_size: config[:lock_release_batch_size],
|
317
317
|
logger: config[:logger],
|
@@ -345,7 +345,7 @@ class RedisQueuedLocks::Client
|
|
345
345
|
# @return [Set<String>,Set<Hash<Symbol,Any>>]
|
346
346
|
#
|
347
347
|
# @api public
|
348
|
-
# @since
|
348
|
+
# @since 1.0.0
|
349
349
|
def locks(scan_size: config[:key_extraction_batch_size], with_info: false)
|
350
350
|
RedisQueuedLocks::Acquier::Locks.locks(redis_client, scan_size:, with_info:)
|
351
351
|
end
|
@@ -356,7 +356,7 @@ class RedisQueuedLocks::Client
|
|
356
356
|
# @return [Set<Hash<String,Any>>]
|
357
357
|
#
|
358
358
|
# @api public
|
359
|
-
# @since
|
359
|
+
# @since 1.0.0
|
360
360
|
def locks_info(scan_size: config[:key_extraction_batch_size])
|
361
361
|
locks(scan_size:, with_info: true)
|
362
362
|
end
|
@@ -376,7 +376,7 @@ class RedisQueuedLocks::Client
|
|
376
376
|
# @return [Set<String>,String<Hash<Symbol,Any>>]
|
377
377
|
#
|
378
378
|
# @api public
|
379
|
-
# @since
|
379
|
+
# @since 1.0.0
|
380
380
|
def queues(scan_size: config[:key_extraction_batch_size], with_info: false)
|
381
381
|
RedisQueuedLocks::Acquier::Queues.queues(redis_client, scan_size:, with_info:)
|
382
382
|
end
|
@@ -387,7 +387,7 @@ class RedisQueuedLocks::Client
|
|
387
387
|
# @return [Set<Hash<Symbol,Any>>]
|
388
388
|
#
|
389
389
|
# @api public
|
390
|
-
# @since
|
390
|
+
# @since 1.0.0
|
391
391
|
def queues_info(scan_size: config[:key_extraction_batch_size])
|
392
392
|
queues(scan_size:, with_info: true)
|
393
393
|
end
|
@@ -396,17 +396,18 @@ class RedisQueuedLocks::Client
|
|
396
396
|
# @return [Set<String>]
|
397
397
|
#
|
398
398
|
# @api public
|
399
|
-
# @since
|
399
|
+
# @since 1.0.0
|
400
400
|
def keys(scan_size: config[:key_extraction_batch_size])
|
401
401
|
RedisQueuedLocks::Acquier::Keys.keys(redis_client, scan_size:)
|
402
402
|
end
|
403
403
|
|
404
404
|
# @option dead_ttl [Integer]
|
405
|
-
#
|
406
|
-
#
|
407
|
-
#
|
405
|
+
# - the time period (in millsiecnds) after whcih the lock request is
|
406
|
+
# considered as dead;
|
407
|
+
# - `config[:dead_request_ttl]` is used by default;
|
408
408
|
# @option scan_size [Integer]
|
409
|
-
#
|
409
|
+
# - the batch of scanned keys for Redis'es SCAN command;
|
410
|
+
# - `config[:lock_release_batch_size]` is used by default;
|
410
411
|
# @option logger [::Logger,#debug]
|
411
412
|
# @option instrumenter [#notify]
|
412
413
|
# @option instrument [NilClass,Any]
|
@@ -414,10 +415,11 @@ class RedisQueuedLocks::Client
|
|
414
415
|
# Format: { ok: true, result: { processed_queus: Set<String> } }
|
415
416
|
#
|
416
417
|
# @api public
|
417
|
-
# @since
|
418
|
+
# @since 1.0.0
|
419
|
+
# @version 1.1.0
|
418
420
|
def clear_dead_requests(
|
419
421
|
dead_ttl: config[:dead_request_ttl],
|
420
|
-
scan_size: config[:
|
422
|
+
scan_size: config[:lock_release_batch_size],
|
421
423
|
logger: config[:logger],
|
422
424
|
instrumenter: config[:instrumenter],
|
423
425
|
instrument: nil
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Debugger::Interface
|
6
6
|
# @param message [String]
|
7
7
|
# @return [void]
|
8
8
|
#
|
9
9
|
# @api private
|
10
|
-
# @since
|
10
|
+
# @since 1.0.0
|
11
11
|
def debug(message)
|
12
12
|
RedisQueuedLocks::Debugger.debug(message)
|
13
13
|
end
|
@@ -15,7 +15,7 @@ module RedisQueuedLocks::Debugger::Interface
|
|
15
15
|
# @return [void]
|
16
16
|
#
|
17
17
|
# @api private
|
18
|
-
# @since
|
18
|
+
# @since 1.0.0
|
19
19
|
def enable_debugger!
|
20
20
|
RedisQueuedLocks::Debugger.enable!
|
21
21
|
end
|
@@ -23,7 +23,7 @@ module RedisQueuedLocks::Debugger::Interface
|
|
23
23
|
# @return [void]
|
24
24
|
#
|
25
25
|
# @api private
|
26
|
-
# @since
|
26
|
+
# @since 1.0.0
|
27
27
|
def disable_debugger!
|
28
28
|
RedisQueuedLocks::Debugger.disable!
|
29
29
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Debugger
|
6
6
|
require_relative 'debugger/interface'
|
7
7
|
|
8
8
|
# @return [String]
|
9
9
|
#
|
10
10
|
# @api private
|
11
|
-
# @since
|
11
|
+
# @since 1.0.0
|
12
12
|
DEBUG_ENABLED_METHOD = <<~METHOD_DECLARATION.strip.freeze
|
13
13
|
def debug(message) = STDOUT.write("#\{message}\n")
|
14
14
|
METHOD_DECLARATION
|
@@ -16,20 +16,20 @@ module RedisQueuedLocks::Debugger
|
|
16
16
|
# @return [String]
|
17
17
|
#
|
18
18
|
# @api private
|
19
|
-
# @since
|
19
|
+
# @since 1.0.0
|
20
20
|
DEBUG_DISABLED_MEHTOD = <<~METHOD_DECLARATION.strip.freeze
|
21
21
|
def debug(message); end
|
22
22
|
METHOD_DECLARATION
|
23
23
|
|
24
24
|
class << self
|
25
25
|
# @api private
|
26
|
-
# @since
|
26
|
+
# @since 1.0.0
|
27
27
|
instance_variable_set(:@enabled, false)
|
28
28
|
|
29
29
|
# @return [void]
|
30
30
|
#
|
31
31
|
# @api private
|
32
|
-
# @since
|
32
|
+
# @since 1.0.0
|
33
33
|
def enable!
|
34
34
|
@enabled = true
|
35
35
|
eval(DEBUG_ENABLED_METHOD)
|
@@ -38,7 +38,7 @@ module RedisQueuedLocks::Debugger
|
|
38
38
|
# @return [void]
|
39
39
|
#
|
40
40
|
# @api private
|
41
|
-
# @since
|
41
|
+
# @since 1.0.0
|
42
42
|
def disable!
|
43
43
|
@enabled = false
|
44
44
|
eval(DEBUG_DISABLED_MEHTOD)
|
@@ -47,7 +47,7 @@ module RedisQueuedLocks::Debugger
|
|
47
47
|
# @return [Boolean]
|
48
48
|
#
|
49
49
|
# @api private
|
50
|
-
# @since
|
50
|
+
# @since 1.0.0
|
51
51
|
def enabled?
|
52
52
|
@enabled
|
53
53
|
end
|
@@ -56,7 +56,7 @@ module RedisQueuedLocks::Debugger
|
|
56
56
|
# @return [void]
|
57
57
|
#
|
58
58
|
# @api private
|
59
|
-
# @since
|
59
|
+
# @since 1.0.0
|
60
60
|
def debug(message); end
|
61
61
|
end
|
62
62
|
end
|
@@ -2,26 +2,26 @@
|
|
2
2
|
|
3
3
|
module RedisQueuedLocks
|
4
4
|
# @api public
|
5
|
-
# @since
|
5
|
+
# @since 1.0.0
|
6
6
|
Error = Class.new(::StandardError)
|
7
7
|
|
8
8
|
# @api public
|
9
|
-
# @since
|
9
|
+
# @since 1.0.0
|
10
10
|
ArgumentError = Class.new(::ArgumentError)
|
11
11
|
|
12
12
|
# @api public
|
13
|
-
# @since
|
13
|
+
# @since 1.0.0
|
14
14
|
LockAlreadyObtainedError = Class.new(Error)
|
15
15
|
|
16
16
|
# @api public
|
17
|
-
# @since
|
17
|
+
# @since 1.0.0
|
18
18
|
LockAcquiermentTimeoutError = Class.new(Error)
|
19
19
|
|
20
20
|
# @api public
|
21
|
-
# @since
|
21
|
+
# @since 1.0.0
|
22
22
|
LockAcquiermentRetryLimitError = Class.new(Error)
|
23
23
|
|
24
24
|
# @api pulic
|
25
|
-
# @since
|
25
|
+
# @since 1.0.0
|
26
26
|
TimedLockTimeoutError = Class.new(Error)
|
27
27
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Instrument::ActiveSupport
|
6
6
|
class << self
|
7
7
|
# @param event [String]
|
@@ -9,7 +9,7 @@ module RedisQueuedLocks::Instrument::ActiveSupport
|
|
9
9
|
# @return [void]
|
10
10
|
#
|
11
11
|
# @api public
|
12
|
-
# @since
|
12
|
+
# @since 1.0.0
|
13
13
|
def notify(event, payload = {})
|
14
14
|
::ActiveSupport::Notifications.instrument(event, payload)
|
15
15
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Instrument::VoidNotifier
|
6
6
|
class << self
|
7
7
|
# @param event [String]
|
@@ -9,7 +9,7 @@ module RedisQueuedLocks::Instrument::VoidNotifier
|
|
9
9
|
# @return [void]
|
10
10
|
#
|
11
11
|
# @api public
|
12
|
-
# @since
|
12
|
+
# @since 1.0.0
|
13
13
|
def notify(event, payload = {}); end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Instrument
|
6
6
|
require_relative 'instrument/void_notifier'
|
7
7
|
require_relative 'instrument/active_support'
|
@@ -11,7 +11,7 @@ module RedisQueuedLocks::Instrument
|
|
11
11
|
# @return [Boolean]
|
12
12
|
#
|
13
13
|
# @api public
|
14
|
-
# @since
|
14
|
+
# @since 1.0.0
|
15
15
|
def valid_interface?(instrumenter)
|
16
16
|
if instrumenter == RedisQueuedLocks::Instrument::ActiveSupport
|
17
17
|
# NOTE: active_support should be required in your app
|
@@ -1,43 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Logging::VoidLogger
|
6
6
|
class << self
|
7
7
|
# @api public
|
8
|
-
# @since
|
8
|
+
# @since 1.0.0
|
9
9
|
def warn(progname = nil, &block); end
|
10
10
|
|
11
11
|
# @api public
|
12
|
-
# @since
|
12
|
+
# @since 1.0.0
|
13
13
|
def unknown(progname = nil, &block); end
|
14
14
|
|
15
15
|
# @api public
|
16
|
-
# @since
|
16
|
+
# @since 1.0.0
|
17
17
|
def log(progname = nil, &block); end
|
18
18
|
|
19
19
|
# @api public
|
20
|
-
# @since
|
20
|
+
# @since 1.0.0
|
21
21
|
def info(progname = nil, &block); end
|
22
22
|
|
23
23
|
# @api public
|
24
|
-
# @since
|
24
|
+
# @since 1.0.0
|
25
25
|
def error(progname = nil, &block); end
|
26
26
|
|
27
27
|
# @api public
|
28
|
-
# @since
|
28
|
+
# @since 1.0.0
|
29
29
|
def fatal(progname = nil, &block); end
|
30
30
|
|
31
31
|
# @api public
|
32
|
-
# @since
|
32
|
+
# @since 1.0.0
|
33
33
|
def debug(progname = nil, &block); end
|
34
34
|
|
35
35
|
# @api public
|
36
|
-
# @since
|
36
|
+
# @since 1.0.0
|
37
37
|
def add(*, &block); end
|
38
38
|
|
39
39
|
# @api public
|
40
|
-
# @since
|
40
|
+
# @since 1.0.0
|
41
41
|
def <<(message); end
|
42
42
|
end
|
43
43
|
end
|
@@ -1,19 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api public
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Logging
|
6
6
|
require_relative 'logging/void_logger'
|
7
7
|
|
8
8
|
class << self
|
9
|
-
# @param logger [::Logger,#debug]
|
9
|
+
# @param logger [::Logger,#debug,::SemanticLogger::Logger]
|
10
10
|
# @return [Boolean]
|
11
11
|
#
|
12
12
|
# @api public
|
13
|
-
# @since
|
13
|
+
# @since 1.0.0
|
14
|
+
# @version 1.2.0
|
14
15
|
def valid_interface?(logger)
|
15
16
|
return true if logger.is_a?(::Logger)
|
16
17
|
|
18
|
+
# NOTE:
|
19
|
+
# - convinient/conventional way to support the popular`semantic_logger` library
|
20
|
+
# - see https://logger.rocketjob.io/
|
21
|
+
# - see https://github.com/reidmorrison/semantic_logger
|
22
|
+
return true if defined?(::SemanticLogger::Logger) && logger.is_a?(::SemanticLogger::Logger)
|
23
|
+
|
17
24
|
# NOTE: should provide `#debug` method.
|
18
25
|
return false unless logger.respond_to?(:debug)
|
19
26
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Resource
|
6
6
|
# @return [String]
|
7
7
|
#
|
8
8
|
# @api private
|
9
|
-
# @since
|
9
|
+
# @since 1.0.0
|
10
10
|
KEY_PATTERN = 'rql:lock*'
|
11
11
|
|
12
12
|
# @return [String]
|
13
13
|
#
|
14
14
|
# @api private
|
15
|
-
# @since
|
15
|
+
# @since 1.0.0
|
16
16
|
LOCK_PATTERN = 'rql:lock:*'
|
17
17
|
|
18
18
|
# @return [String]
|
19
19
|
#
|
20
20
|
# @api private
|
21
|
-
# @since
|
21
|
+
# @since 1.0.0
|
22
22
|
LOCK_QUEUE_PATTERN = 'rql:lock_queue:*'
|
23
23
|
|
24
24
|
class << self
|
@@ -29,7 +29,7 @@ module RedisQueuedLocks::Resource
|
|
29
29
|
# @return [String]
|
30
30
|
#
|
31
31
|
# @api private
|
32
|
-
# @since
|
32
|
+
# @since 1.0.0
|
33
33
|
def calc_uniq_identity
|
34
34
|
SecureRandom.hex(8)
|
35
35
|
end
|
@@ -42,7 +42,7 @@ module RedisQueuedLocks::Resource
|
|
42
42
|
# @return [String]
|
43
43
|
#
|
44
44
|
# @api private
|
45
|
-
# @since
|
45
|
+
# @since 1.0.0
|
46
46
|
def acquier_identifier(process_id, thread_id, fiber_id, ractor_id, identity)
|
47
47
|
"rql:acq:#{process_id}/#{thread_id}/#{fiber_id}/#{ractor_id}/#{identity}"
|
48
48
|
end
|
@@ -51,7 +51,7 @@ module RedisQueuedLocks::Resource
|
|
51
51
|
# @return [String]
|
52
52
|
#
|
53
53
|
# @api private
|
54
|
-
# @since
|
54
|
+
# @since 1.0.0
|
55
55
|
def prepare_lock_key(lock_name)
|
56
56
|
"rql:lock:#{lock_name}"
|
57
57
|
end
|
@@ -60,7 +60,7 @@ module RedisQueuedLocks::Resource
|
|
60
60
|
# @return [String]
|
61
61
|
#
|
62
62
|
# @api private
|
63
|
-
# @since
|
63
|
+
# @since 1.0.0
|
64
64
|
def prepare_lock_queue(lock_name)
|
65
65
|
"rql:lock_queue:#{lock_name}"
|
66
66
|
end
|
@@ -68,7 +68,7 @@ module RedisQueuedLocks::Resource
|
|
68
68
|
# @return [Float] Redis's <Set> score that is calculated from the time (epoch) as a float.
|
69
69
|
#
|
70
70
|
# @api private
|
71
|
-
# @since
|
71
|
+
# @since 1.0.0
|
72
72
|
def calc_initial_acquier_position
|
73
73
|
Time.now.to_f
|
74
74
|
end
|
@@ -77,7 +77,7 @@ module RedisQueuedLocks::Resource
|
|
77
77
|
# @return [Float] Redis's <Set> score barrier for acquiers that should be removed from queue.
|
78
78
|
#
|
79
79
|
# @api private
|
80
|
-
# @since
|
80
|
+
# @since 1.0.0
|
81
81
|
def acquier_dead_score(queue_ttl)
|
82
82
|
Time.now.to_f - queue_ttl
|
83
83
|
end
|
@@ -91,7 +91,7 @@ module RedisQueuedLocks::Resource
|
|
91
91
|
# Is the lock request time limit has reached or not.
|
92
92
|
#
|
93
93
|
# @api private
|
94
|
-
# @since
|
94
|
+
# @since 1.0.0
|
95
95
|
def dead_score_reached?(acquier_position, queue_ttl)
|
96
96
|
(acquier_position + queue_ttl) < Time.now.to_f
|
97
97
|
end
|
@@ -100,7 +100,7 @@ module RedisQueuedLocks::Resource
|
|
100
100
|
# @return [String]
|
101
101
|
#
|
102
102
|
# @api private
|
103
|
-
# @since
|
103
|
+
# @since 1.0.0
|
104
104
|
def lock_key_from_queue(lock_queue)
|
105
105
|
# NOTE: 15 is a start position of the lock name
|
106
106
|
"rql:lock:#{lock_queue[15..]}"
|
@@ -109,7 +109,7 @@ module RedisQueuedLocks::Resource
|
|
109
109
|
# @return [Integer]
|
110
110
|
#
|
111
111
|
# @api private
|
112
|
-
# @since
|
112
|
+
# @since 1.0.0
|
113
113
|
def get_thread_id
|
114
114
|
::Thread.current.object_id
|
115
115
|
end
|
@@ -117,7 +117,7 @@ module RedisQueuedLocks::Resource
|
|
117
117
|
# @return [Integer]
|
118
118
|
#
|
119
119
|
# @api private
|
120
|
-
# @since
|
120
|
+
# @since 1.0.0
|
121
121
|
def get_fiber_id
|
122
122
|
::Fiber.current.object_id
|
123
123
|
end
|
@@ -125,7 +125,7 @@ module RedisQueuedLocks::Resource
|
|
125
125
|
# @return [Integer]
|
126
126
|
#
|
127
127
|
# @api private
|
128
|
-
# @since
|
128
|
+
# @since 1.0.0
|
129
129
|
def get_ractor_id
|
130
130
|
::Ractor.current.object_id
|
131
131
|
end
|
@@ -133,7 +133,7 @@ module RedisQueuedLocks::Resource
|
|
133
133
|
# @return [Integer]
|
134
134
|
#
|
135
135
|
# @api private
|
136
|
-
# @since
|
136
|
+
# @since 1.0.0
|
137
137
|
def get_process_id
|
138
138
|
::Process.pid
|
139
139
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since
|
4
|
+
# @since 1.0.0
|
5
5
|
module RedisQueuedLocks::Utilities
|
6
6
|
module_function
|
7
7
|
|
@@ -9,7 +9,7 @@ module RedisQueuedLocks::Utilities
|
|
9
9
|
# @return [Any]
|
10
10
|
#
|
11
11
|
# @api private
|
12
|
-
# @since
|
12
|
+
# @since 1.0.0
|
13
13
|
def run_non_critical(&block)
|
14
14
|
yield rescue nil
|
15
15
|
end
|
data/lib/redis_queued_locks.rb
CHANGED
@@ -7,7 +7,7 @@ require 'securerandom'
|
|
7
7
|
require 'logger'
|
8
8
|
|
9
9
|
# @api public
|
10
|
-
# @since
|
10
|
+
# @since 1.0.0
|
11
11
|
module RedisQueuedLocks
|
12
12
|
require_relative 'redis_queued_locks/version'
|
13
13
|
require_relative 'redis_queued_locks/errors'
|
@@ -20,6 +20,6 @@ module RedisQueuedLocks
|
|
20
20
|
require_relative 'redis_queued_locks/instrument'
|
21
21
|
require_relative 'redis_queued_locks/client'
|
22
22
|
|
23
|
-
# @since
|
23
|
+
# @since 1.0.0
|
24
24
|
extend RedisQueuedLocks::Debugger::Interface
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_queued_locks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.5.1
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Queued distributed locks based on Redis.
|