redis_queued_locks 0.0.3 → 0.0.4
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 +4 -0
- data/README.md +62 -1
- data/lib/redis_queued_locks/client.rb +4 -4
- data/lib/redis_queued_locks/version.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e1e1a54762132f92451d595938cb467b7b644dffc0817abe99209e1f92160f8
|
4
|
+
data.tar.gz: 297eec3d7fcee35d12e7f3509e8e3dfd4b8b3c52889c7570a79cd6a30f45eda4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2c64622bd3b8465a749b5f6a8050d5fd1d5b623990f91421f91004c444baab12114964ded28d5ac0fa43fed56f3e893798feb31b00ab173d536e57fcfdfaa4
|
7
|
+
data.tar.gz: 02ee9d8742ffd3a7b16b8c23b8d4c4f58a8cb1b9db4d215ece4bf34de0c79830bd3417186b2d75dbbd48f6845d736361af7503f641e7faa16d139cbe193263d3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,67 @@
|
|
2
2
|
|
3
3
|
Distributed lock implementation with "lock acquisition queue" capabilities based on the Redis Database.
|
4
4
|
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
redis_client = RedisClient.config.new_pool # NOTE: provide your own RedisClient instance
|
9
|
+
|
10
|
+
clinet = RedisQueuedLocks::Client.new(redis_client) do |config|
|
11
|
+
# (default: 3) (supports nil)
|
12
|
+
# - nil means "infinite retries" and you are only limited by the "try_to_lock_timeout" config;
|
13
|
+
config.retry_count = 3
|
14
|
+
|
15
|
+
# (milliseconds) (default: 200)
|
16
|
+
config.retry_delay = 200
|
17
|
+
|
18
|
+
# (milliseconds) (default: 50)
|
19
|
+
config.retry_jitter = 50
|
20
|
+
|
21
|
+
# (seconds) (supports nil)
|
22
|
+
# - nil means "no timeout" and you are only limited by "retry_count" config;
|
23
|
+
config.try_to_lock_timeout = 10
|
24
|
+
|
25
|
+
# (milliseconds) (default: 1)
|
26
|
+
# - expiration precision. affects the ttl (ttl + precision);
|
27
|
+
config.exp_precision = 1
|
28
|
+
|
29
|
+
# (milliseconds) (default: 5_000)
|
30
|
+
# - lock's time to live
|
31
|
+
config.default_lock_ttl = 5_000
|
32
|
+
|
33
|
+
# (seconds) (default: 15)
|
34
|
+
# - lock request timeout. after this timeout your lock request in queue will be requeued;
|
35
|
+
config.default_queue_ttl = 15
|
36
|
+
|
37
|
+
# (default: 100)
|
38
|
+
# - how many items will be released at a time in RedisQueuedLocks::Client#clear_locks logic;
|
39
|
+
# - affects the performancs capabilites (redis, rubyvm);
|
40
|
+
config.lock_release_batch_size = 100
|
41
|
+
|
42
|
+
# (default: RedisQueuedLocks::Instrument::VoidNotifier)
|
43
|
+
# - instrumentation layer;
|
44
|
+
# - you can provde your own instrumenter with `#notify(event, payload = {})`
|
45
|
+
# - event: <string> requried;
|
46
|
+
# - payload: <hash> requried;
|
47
|
+
# - disabled by default via VoidNotifier;
|
48
|
+
config.instrumenter = RedisQueuedLocks::Instrument::ActiveSupport
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
redis_clinet = RedisClient.config.new_pool # NOTE: provide your ounw RedisClient instance
|
56
|
+
rq_lock = RedisQueuedLocks::Client.new(redis_client) do |config|
|
57
|
+
# NOTE: some your application-related configs
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
- `#lock`
|
62
|
+
- `#lock!`
|
63
|
+
- `#unlock`
|
64
|
+
- `#clear_locks`
|
65
|
+
|
5
66
|
## Instrumentation events
|
6
67
|
|
7
68
|
- `"redis_queued_locks.lock_obtained"`
|
@@ -32,6 +93,6 @@ Distributed lock implementation with "lock acquisition queue" capabilities based
|
|
32
93
|
- `"redis_queued_locks.explicit_all_locks_release"`
|
33
94
|
- an event signalizes about the explicit all locks release (invoked via `RedisQueuedLock#clear_locks`);
|
34
95
|
- payload:
|
35
|
-
- `rel_time` - `float`/`milliseconds` - time spent on
|
96
|
+
- `rel_time` - `float`/`milliseconds` - time spent on "realese all locks" operation;
|
36
97
|
- `at` - `integer`/`epoch` - the time when the operation has ended;
|
37
98
|
- `rel_keys` - `integer` - released redis keys count (`released queu keys` + `released lock keys`);
|
@@ -10,10 +10,10 @@ class RedisQueuedLocks::Client
|
|
10
10
|
setting :retry_count, 3
|
11
11
|
setting :retry_delay, 200 # NOTE: milliseconds
|
12
12
|
setting :retry_jitter, 50 # NOTE: milliseconds
|
13
|
-
setting :
|
13
|
+
setting :try_to_lock_timeout, 10 # NOTE: seconds
|
14
14
|
setting :exp_precision, 1 # NOTE: milliseconds
|
15
15
|
setting :default_lock_ttl, 5_000 # NOTE: milliseconds
|
16
|
-
setting :default_queue_ttl,
|
16
|
+
setting :default_queue_ttl, 15 # NOTE: seconds
|
17
17
|
setting :lock_release_batch_size, 100
|
18
18
|
setting :instrumenter, RedisQueuedLocks::Instrument::VoidNotifier
|
19
19
|
|
@@ -23,7 +23,7 @@ class RedisQueuedLocks::Client
|
|
23
23
|
validate('retry_count') { |val| val == nil || (val.is_a?(::Integer) && val >= 0) }
|
24
24
|
validate('retry_delay', :integer)
|
25
25
|
validate('retry_jitter', :integer)
|
26
|
-
validate('
|
26
|
+
validate('try_to_lock_timeout') { |val| val == nil || (val.is_a?(::Integer) && val >= 0) }
|
27
27
|
validate('exp_precision', :integer)
|
28
28
|
validate('default_lock_tt', :integer)
|
29
29
|
validate('default_queue_ttl', :integer)
|
@@ -86,7 +86,7 @@ class RedisQueuedLocks::Client
|
|
86
86
|
thread_id: RedisQueuedLocks::Resource.get_thread_id,
|
87
87
|
ttl: config[:default_lock_ttl],
|
88
88
|
queue_ttl: config[:default_queue_ttl],
|
89
|
-
timeout: config[:
|
89
|
+
timeout: config[:try_to_lock_timeout],
|
90
90
|
retry_count: config[:retry_count],
|
91
91
|
retry_delay: config[:retry_delay],
|
92
92
|
retry_jitter: config[:retry_jitter],
|