redis_queued_locks 0.0.12 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +37 -22
- data/lib/redis_queued_locks/acquier/try.rb +1 -1
- data/lib/redis_queued_locks/acquier.rb +4 -3
- data/lib/redis_queued_locks/client.rb +4 -1
- data/lib/redis_queued_locks/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b4ae233fe0c41b159f78f44fde1623d54e5bb80bc675c06e11d89741f41cc8d
|
4
|
+
data.tar.gz: 0c79574d32f3e807d7005e64616ce316be64e3e8553df8e65d15e821ee3e0559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0cbdc2c84e9b5da48008a881fe2994bbdaba859d1795cd599d272acb6004c445b3784c311d90f1924bf74c161a58784d6025b3185f3da02f6f97486783eb81
|
7
|
+
data.tar.gz: 61c730ae6bdd25a3a49ca4da36388e9c08280e36eb83de6edaf6dc879b447c5109e6321e7e8b160a973d5eb8abfcb35d8090984f26aca04c738ad7a6e797c967
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.0.14] - 2024-02-28
|
4
|
+
### Changed
|
5
|
+
- Minor documentation updates;
|
6
|
+
|
7
|
+
## [0.0.13] - 2024-02-27
|
8
|
+
### Changed
|
9
|
+
- Minor development updates;
|
10
|
+
|
3
11
|
## [0.0.12] - 2024-02-27
|
4
12
|
### Changed
|
5
13
|
- Deleted `redis expiration error` (1 millisecond time drift) from lock ttl calculation;
|
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
|
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
|
-
|
195
|
-
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
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,
|
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
|
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,
|
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
|
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
|
-
#
|
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
|
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
|
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.
|
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.
|
95
|
+
rubygems_version: 3.3.7
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Queued distributed locks based on Redis.
|