redis_queued_locks 0.0.13 → 0.0.14

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
  SHA256:
3
- metadata.gz: '0067915f812330a031b51bc20300a13eee31aa2628aa2b26c90524c58d80ab60'
4
- data.tar.gz: f322cbff42c80656ad09d075008c48461db991c153ab04b42e4187f54bcc6bce
3
+ metadata.gz: 5b4ae233fe0c41b159f78f44fde1623d54e5bb80bc675c06e11d89741f41cc8d
4
+ data.tar.gz: 0c79574d32f3e807d7005e64616ce316be64e3e8553df8e65d15e821ee3e0559
5
5
  SHA512:
6
- metadata.gz: fbe61d02314ec926529a30cb3771903199897b798f386ff6a5ebb562d3857b92c11d5579a4d6cc9219fa64e152ff1e4f6aeb1ceb98cf8eae094c443b8ec2f6b9
7
- data.tar.gz: 3462b766ffb13ca57d21caa7d4725b076a3dc6c594601288f8c7593cb496f58d3ce4b66082035d8ab4bbfa3eba395db475995cacb3a4eb588b03ab06a25eef27
6
+ metadata.gz: 9a0cbdc2c84e9b5da48008a881fe2994bbdaba859d1795cd599d272acb6004c445b3784c311d90f1924bf74c161a58784d6025b3185f3da02f6f97486783eb81
7
+ data.tar.gz: 61c730ae6bdd25a3a49ca4da36388e9c08280e36eb83de6edaf6dc879b447c5109e6321e7e8b160a973d5eb8abfcb35d8090984f26aca04c738ad7a6e797c967
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.14] - 2024-02-28
4
+ ### Changed
5
+ - Minor documentation updates;
6
+
3
7
  ## [0.0.13] - 2024-02-27
4
8
  ### Changed
5
9
  - Minor development updates;
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Distributed locks with "lock acquisition queue" capabilities based on the Redis Database.
4
4
 
5
- Each lock request is put into a request queue and processed in order of their priority (FIFO).
5
+ Each lock request is put into the request queue and processed in order of their priority (FIFO). Each lock request lives some period of time (RTTL) which guarantees that the request queue will never be stacked.
6
6
 
7
7
  ---
8
8
 
@@ -145,6 +145,8 @@ end
145
145
 
146
146
  - If block is passed the obtained lock will be released after the block execution or the lock's ttl (what will happen first);
147
147
  - If block is not passed the obtained lock will be released after lock's ttl;
148
+ - If block is passed the block's yield result will be returned;
149
+ - If block is not passed the lock information will be returned;
148
150
 
149
151
  ```ruby
150
152
  def lock(
@@ -191,25 +193,30 @@ def lock(
191
193
  - If block is **not passed** the obtained lock will be released after it's ttl;
192
194
 
193
195
  Return value:
194
- - `[Hash<Symbol,Any>]` Format: `{ ok: true/false, result: Symbol/Hash }`;
195
- - for successful lock obtaining:
196
- ```ruby
197
- {
198
- ok: true,
199
- result: {
200
- lock_key: String, # acquierd lock key ("rql:lock:your_lock_name")
201
- acq_id: String, # acquier identifier ("process_id/thread_id/fiber_id/ractor_id/identity")
202
- ts: Integer, # time (epoch) when lock was obtained (integer)
203
- ttl: Integer # lock's time to live in milliseconds (integer)
196
+
197
+ - If block is passed the block's yield result will be returned;
198
+ - If block is not passed the lock information will be returned;
199
+ - Lock information result:
200
+ - Signature: `[yield, Hash<Symbol,Boolean|Hash<Symbol,Numeric|String>>]`
201
+ - Format: `{ ok: true/false, result: <Symbol|Hash<Symbol,Hash>> }`;
202
+ - for successful lock obtaining:
203
+ ```ruby
204
+ {
205
+ ok: true,
206
+ result: {
207
+ lock_key: String, # acquierd lock key ("rql:lock:your_lock_name")
208
+ acq_id: String, # acquier identifier ("process_id/thread_id/fiber_id/ractor_id/identity")
209
+ ts: Integer, # time (epoch) when lock was obtained (integer)
210
+ ttl: Integer # lock's time to live in milliseconds (integer)
211
+ }
204
212
  }
205
- }
206
- ```
207
- - for failed lock obtaining:
208
- ```ruby
209
- { ok: false, result: :timeout_reached }
210
- { ok: false, result: :retry_count_reached }
211
- { ok: false, result: :unknown }
212
- ```
213
+ ```
214
+ - for failed lock obtaining:
215
+ ```ruby
216
+ { ok: false, result: :timeout_reached }
217
+ { ok: false, result: :retry_count_reached }
218
+ { ok: false, result: :unknown }
219
+ ```
213
220
 
214
221
  ---
215
222
 
@@ -277,6 +284,14 @@ rql.lock_info("your_lock_name")
277
284
  - `acq_id` - `string` - acquier identifier (process_id/thread_id/fiber_id/ractor_id/identity by default);
278
285
  - `score` - `float`/`epoch` - time when the lock request was made (epoch);
279
286
 
287
+ ```
288
+ | Returns an information about the required lock queue by the lock name. The result
289
+ | represnts the ordered lock request queue that is ordered by score (Redis sets) and shows
290
+ | lock acquirers and their position in queue. Async nature with redis communcation can lead
291
+ | the situation when the queue becomes empty during the queue data extraction. So sometimes
292
+ | you can receive the lock queue info with empty queue value (an empty array).
293
+ ```
294
+
280
295
  ```ruby
281
296
  rql.queue_info("your_lock_name")
282
297
 
@@ -327,7 +342,7 @@ def unlock(lock_name)
327
342
  - the lock name that should be released.
328
343
 
329
344
  Return:
330
- - `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric|String> }`;
345
+ - `[Hash<Symbol,Numeric|String>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric|String> }`;
331
346
 
332
347
  ```ruby
333
348
  {
@@ -352,10 +367,10 @@ def clear_locks(batch_size: config[:lock_release_batch_size])
352
367
  ```
353
368
 
354
369
  - `batch_size` - `[Integer]`
355
- - batch of cleared locks and lock queus unde the one pipelined redis command;
370
+ - the size of batch of locks and lock queus that should be cleared under the one pipelined redis command at once;
356
371
 
357
372
  Return:
358
- - `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric> }`;
373
+ - `[Hash<Symbol,Numeric>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric> }`;
359
374
 
360
375
  ```ruby
361
376
  {
@@ -104,7 +104,7 @@ module RedisQueuedLocks::Acquier::Try
104
104
  )
105
105
 
106
106
  # Step 6.3: set the lock expiration time in order to prevent "infinite locks"
107
- transact.call('PEXPIRE', lock_key, ttl) # NOTE: in seconds
107
+ transact.call('PEXPIRE', lock_key, ttl) # NOTE: in milliseconds
108
108
  end
109
109
  end
110
110
  end
@@ -60,8 +60,9 @@ module RedisQueuedLocks::Acquier
60
60
  # represented as 10 bytes hexstr.
61
61
  # @param [Block]
62
62
  # A block of code that should be executed after the successfully acquired lock.
63
- # @return [Hash<Symbol,Any>]
64
- # Format: { ok: true/false, result: Any }
63
+ # @return [Hash<Symbol,Any>,yield]
64
+ # - Format: { ok: true/false, result: Any }
65
+ # - If block is given the result of block's yeld will be returned.
65
66
  #
66
67
  # @api private
67
68
  # @since 0.1.0
@@ -363,7 +364,7 @@ module RedisQueuedLocks::Acquier
363
364
  # Returns an information about the required lock queue by the lock name. The result
364
365
  # represnts the ordered lock request queue that is ordered by score (Redis sets) and shows
365
366
  # lock acquirers and their position in queue. Async nature with redis communcation can lead
366
- # the sitation when the queue becomes empty during the queue data extraction. So sometimes
367
+ # the sitaution when the queue becomes empty during the queue data extraction. So sometimes
367
368
  # you can receive the lock queue info with empty queue.
368
369
  #
369
370
  # @param redis_client [RedisClient]
@@ -43,6 +43,8 @@ class RedisQueuedLocks::Client
43
43
  # @api private
44
44
  # @since 0.1.0
45
45
  attr_accessor :uniq_identity
46
+ # NOTE: attr_access is chosen intentionally in order to have an ability to change
47
+ # uniq_identity values for debug purposes in runtime;
46
48
 
47
49
  # @param redis_client [RedisClient]
48
50
  # Redis connection manager, which will be used for the lock acquierment and distribution.
@@ -84,7 +86,8 @@ class RedisQueuedLocks::Client
84
86
  # @param block [Block]
85
87
  # A block of code that should be executed after the successfully acquired lock.
86
88
  # @return [Hash<Symbol,Any>,yield]
87
- # Format: { ok: true/false, result: Symbol/Hash }.
89
+ # - Format: { ok: true/false, result: Symbol/Hash }.
90
+ # - If block is given the result of block's yeld will be returned.
88
91
  #
89
92
  # @api public
90
93
  # @since 0.1.0
@@ -5,6 +5,6 @@ module RedisQueuedLocks
5
5
  #
6
6
  # @api public
7
7
  # @since 0.0.1
8
- # @version 0.0.13
9
- VERSION = '0.0.13'
8
+ # @version 0.0.14
9
+ VERSION = '0.0.14'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_queued_locks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.5.1
95
+ rubygems_version: 3.3.7
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Queued distributed locks based on Redis.