redis_queued_locks 0.0.19 → 0.0.21

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.
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.1.0
5
+ module RedisQueuedLocks::Utilities
6
+ module_function
7
+
8
+ # @param block [Block]
9
+ # @return [Any]
10
+ #
11
+ # @api private
12
+ # @since 0.1.0
13
+ def run_non_critical(&block)
14
+ yield rescue nil
15
+ end
16
+ end
@@ -5,6 +5,6 @@ module RedisQueuedLocks
5
5
  #
6
6
  # @api public
7
7
  # @since 0.0.1
8
- # @version 0.0.19
9
- VERSION = '0.0.19'
8
+ # @version 0.0.21
9
+ VERSION = '0.0.21'
10
10
  end
@@ -10,6 +10,7 @@ require 'securerandom'
10
10
  module RedisQueuedLocks
11
11
  require_relative 'redis_queued_locks/version'
12
12
  require_relative 'redis_queued_locks/errors'
13
+ require_relative 'redis_queued_locks/utilities'
13
14
  require_relative 'redis_queued_locks/data'
14
15
  require_relative 'redis_queued_locks/debugger'
15
16
  require_relative 'redis_queued_locks/resource'
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: 0.0.19
4
+ version: 0.0.21
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-03-12 00:00:00.000000000 Z
11
+ date: 2024-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client
@@ -56,10 +56,21 @@ files:
56
56
  - Rakefile
57
57
  - lib/redis_queued_locks.rb
58
58
  - lib/redis_queued_locks/acquier.rb
59
- - lib/redis_queued_locks/acquier/delay.rb
60
- - lib/redis_queued_locks/acquier/release.rb
61
- - lib/redis_queued_locks/acquier/try.rb
62
- - lib/redis_queued_locks/acquier/yield_expire.rb
59
+ - lib/redis_queued_locks/acquier/acquire_lock.rb
60
+ - lib/redis_queued_locks/acquier/acquire_lock/delay_execution.rb
61
+ - lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb
62
+ - lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb
63
+ - lib/redis_queued_locks/acquier/acquire_lock/yield_with_expire.rb
64
+ - lib/redis_queued_locks/acquier/extend_lock_ttl.rb
65
+ - lib/redis_queued_locks/acquier/is_locked.rb
66
+ - lib/redis_queued_locks/acquier/is_queued.rb
67
+ - lib/redis_queued_locks/acquier/keys.rb
68
+ - lib/redis_queued_locks/acquier/lock_info.rb
69
+ - lib/redis_queued_locks/acquier/locks.rb
70
+ - lib/redis_queued_locks/acquier/queue_info.rb
71
+ - lib/redis_queued_locks/acquier/queues.rb
72
+ - lib/redis_queued_locks/acquier/release_all_locks.rb
73
+ - lib/redis_queued_locks/acquier/release_lock.rb
63
74
  - lib/redis_queued_locks/client.rb
64
75
  - lib/redis_queued_locks/data.rb
65
76
  - lib/redis_queued_locks/debugger.rb
@@ -69,6 +80,7 @@ files:
69
80
  - lib/redis_queued_locks/instrument/active_support.rb
70
81
  - lib/redis_queued_locks/instrument/void_notifier.rb
71
82
  - lib/redis_queued_locks/resource.rb
83
+ - lib/redis_queued_locks/utilities.rb
72
84
  - lib/redis_queued_locks/version.rb
73
85
  - redis_queued_locks.gemspec
74
86
  homepage: https://github.com/0exp/redis_queued_locks
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.1.0
5
- module RedisQueuedLocks::Acquier::Release
6
- # Realease the lock: clear the lock queue and expire the lock.
7
- #
8
- # @param redis [RedisClient]
9
- # @param lock_key [String]
10
- # @param lock_key_queue [String]
11
- # @return [RedisQueuedLocks::Data,Hash<Symbol,Any>] Format: { ok: true/false, result: Any }
12
- #
13
- # @api private
14
- # @since 0.1.0
15
- def fully_release_lock(redis, lock_key, lock_key_queue)
16
- result = redis.multi do |transact|
17
- transact.call('ZREMRANGEBYSCORE', lock_key_queue, '-inf', '+inf')
18
- transact.call('EXPIRE', lock_key, '0')
19
- end
20
-
21
- RedisQueuedLocks::Data[ok: true, result:]
22
- end
23
-
24
- # Release all locks: clear all lock queus and expire all locks.
25
- #
26
- # @param redis [RedisClient]
27
- # @param batch_size [Integer]
28
- # @return [RedisQueuedLocks::Data,Hash<Symbol,Any>] Format: { ok: true/false, result: Any }
29
- #
30
- # @api private
31
- # @since 0.1.0
32
- def fully_release_all_locks(redis, batch_size)
33
- result = redis.pipelined do |pipeline|
34
- # Step A: release all queus and their related locks
35
- redis.scan(
36
- 'MATCH',
37
- RedisQueuedLocks::Resource::LOCK_QUEUE_PATTERN,
38
- count: batch_size
39
- ) do |lock_queue|
40
- # TODO: reduce unnecessary iterations
41
- pipeline.call('ZREMRANGEBYSCORE', lock_queue, '-inf', '+inf')
42
- pipeline.call('EXPIRE', RedisQueuedLocks::Resource.lock_key_from_queue(lock_queue), '0')
43
- end
44
-
45
- # Step B: release all locks
46
- redis.scan(
47
- 'MATCH',
48
- RedisQueuedLocks::Resource::LOCK_PATTERN,
49
- count: batch_size
50
- ) do |lock_key|
51
- # TODO: reduce unnecessary iterations
52
- pipeline.call('EXPIRE', lock_key, '0')
53
- end
54
- end
55
-
56
- rel_keys = result.count { |red_res| red_res == 0 }
57
-
58
- RedisQueuedLocks::Data[ok: true, result: { rel_keys: rel_keys }]
59
- end
60
- end