potlock 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +27 -3
- data/Gemfile.lock +1 -1
- data/README.md +29 -32
- data/lib/potlock/client.rb +5 -1
- data/lib/potlock/version.rb +1 -1
- metadata +7 -8
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd962c3aa384567b6785cb2e7a82a8fb31d50be3b2c3f228c249f72edf47800
|
4
|
+
data.tar.gz: 6a78df19b8bc6d5c6dd70789529f557159a34446288f60c0433666b7a0576fe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01cedb4706077fcfa12a778302d6a2878d368ac97379990001439ad2e149161bdccab46e4605be6c7514c3ddb7049331692559da6bc6d8cceb8a66e5cbd837df
|
7
|
+
data.tar.gz: c0714d34a48015e239baca0d65ada1297d25245570d1365c8c47cfc31c9024c8e3dc5a2aceb4481a86a521a9699dd64268b883eef5081d3b1f9040c9c2a3760b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
|
-
## [
|
1
|
+
## [0.1.0] - 2021-09-29
|
2
2
|
|
3
|
-
|
3
|
+
- ebbcda8 Update Gemfile.lock
|
4
|
+
- d07268d Bump version
|
5
|
+
- 81c86c4 Fix retry delay when locking a key
|
4
6
|
|
5
|
-
-
|
7
|
+
## [0.1.0] - 2021-09-16
|
8
|
+
|
9
|
+
- 5ba7a8f Update `README.md` with Errors handling
|
10
|
+
- 53ce701 Fix company github url
|
11
|
+
- c3b8799 Update `README.md`
|
12
|
+
- 4696ef6 Use ruby matrix rather than specific version
|
13
|
+
- 922df46 Update `README.md`
|
14
|
+
- 1b62b90 Add Rubygems badge
|
15
|
+
- 9619e6f Ignore .gem files
|
16
|
+
- c596b5f Add Rubocop badge to `README.md`
|
17
|
+
- 9321e09 Add badges to `README.md`
|
18
|
+
- 1dbad1c Revert - Ignore Markdown files in Github Actions
|
19
|
+
- 8a9b733 Ignore Markdown files in Github Actions
|
20
|
+
- ea33fe3 Ignore Markdown files in Github Actions
|
21
|
+
- f56902d Update docs regarding Potloc open source template
|
22
|
+
- fbb3e4b Create SECURITY.md
|
23
|
+
- 23b37cf Use of MockRedis rather than a Redis service
|
24
|
+
- 48f6d7f Exclude potlock.gemspec from rubocop BlockLength
|
25
|
+
- 220d349 Remove redis env var for rspec
|
26
|
+
- df02e5a Add environment variable support for Redis connection
|
27
|
+
- 072cac7 Add Redis Service
|
28
|
+
- 2544ed5 Fix Gemfile.lock
|
29
|
+
- b4ea739 Initial commit
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,22 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
</a>
|
8
|
-
|
9
|
-
<a href="CONTRIBUTING.md">
|
10
|
-
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome!" />
|
11
|
-
</a>
|
12
|
-
|
13
|
-
<a href="https://github.com/POTLOC/potlock/actions/workflows/rspec.yml">
|
14
|
-
<img src="https://github.com/POTLOC/potlock/actions/workflows/rspec.yml/badge.svg?branch=main" alt="RSpec tests" />
|
15
|
-
</a>
|
16
|
-
|
17
|
-
<a href="https://github.com/POTLOC/potlock/actions/workflows/rubocop.yml">
|
18
|
-
<img src="https://github.com/POTLOC/potlock/actions/workflows/rubocop.yml/badge.svg?branch=main" alt="Rubocop" />
|
19
|
-
</a>
|
1
|
+
[![Potlock is released under the MIT license.](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
|
2
|
+
[![The code of conduct of Potlock.](https://img.shields.io/badge/Contributor%20Covenant-2.1-blue.svg)](CODE_OF_CONDUCT.md)
|
3
|
+
[![PRs welcome!](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
|
4
|
+
[![RSpec tests](https://github.com/potloc/potlock/actions/workflows/rspec.yml/badge.svg)](https://github.com/potloc/potlock/actions/workflows/rspec.yml)
|
5
|
+
[![Rubocop](https://github.com/potloc/potlock/actions/workflows/rubocop.yml/badge.svg)](https://github.com/potloc/potlock/actions/workflows/rubocop.yml)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/potlock.svg)](https://badge.fury.io/rb/potlock)
|
20
7
|
|
21
8
|
# Potlock - Distributed Read-Write lock using redis
|
22
9
|
|
@@ -26,16 +13,11 @@ Allows only one concurrent reader or writer. And if the lock is taken, any reade
|
|
26
13
|
|
27
14
|
Highly relying on https://github.com/leandromoreira/redlock-rb.
|
28
15
|
|
29
|
-
_Interested in what we do at [Potloc](https://jobs.lever.co/Potloc)? Come join us! We are hiring 🚀_
|
30
|
-
|
31
|
-
<a href="https://jobs.lever.co/Potloc">
|
32
|
-
<img src="https://www.potloc.com/hubfs/raw_assets/public/Potloc_February2021/images/potloc-logo-5887eaeeeb6a65da7d364097a7edee175590aed00ec877d1c6c64ea955a51a5f.svg" alt="Potloc" width="236" height="54"></a>
|
33
|
-
|
34
16
|
## Compatibility
|
35
17
|
|
36
18
|
Potlock works with Redis versions 2.6 or later.
|
37
19
|
|
38
|
-
##
|
20
|
+
## Getting started 🚀
|
39
21
|
|
40
22
|
Add this line to your application's Gemfile:
|
41
23
|
|
@@ -56,14 +38,15 @@ Or install it yourself as:
|
|
56
38
|
### Initialize the lock
|
57
39
|
|
58
40
|
```ruby
|
59
|
-
|
41
|
+
redis_key = "hello_world" # The Redis key you want to read or write
|
42
|
+
lock = Potlock::Client.new(key: redis_key)
|
60
43
|
```
|
61
44
|
There's a list of options you can pass as described [here](#redis-client-configuration).
|
62
45
|
|
63
46
|
### Get a value from Redis
|
64
47
|
|
65
48
|
```ruby
|
66
|
-
# Will wait until all locks are freed before getting "
|
49
|
+
# Will wait until all locks are freed before getting the key "hello_world".
|
67
50
|
value = lock.get
|
68
51
|
```
|
69
52
|
|
@@ -71,7 +54,7 @@ value = lock.get
|
|
71
54
|
|
72
55
|
```ruby
|
73
56
|
lock.set do
|
74
|
-
# Execute this block and set the return value in "
|
57
|
+
# Execute this block and set the return value in the key "hello_world"
|
75
58
|
end
|
76
59
|
```
|
77
60
|
|
@@ -79,7 +62,21 @@ end
|
|
79
62
|
|
80
63
|
```ruby
|
81
64
|
value = lock.fetch do
|
82
|
-
# Fetch "
|
65
|
+
# Fetch the key "hello_world" in Redis or execute this block if not present
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### Errors handling
|
70
|
+
|
71
|
+
In case of the lock can't get acquired, an exception is raised:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
begin
|
75
|
+
lock.set do
|
76
|
+
# critical code
|
77
|
+
end
|
78
|
+
rescue Potlock::LockError
|
79
|
+
# error handling
|
83
80
|
end
|
84
81
|
```
|
85
82
|
|
@@ -112,9 +109,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
112
109
|
|
113
110
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
114
111
|
|
115
|
-
##
|
112
|
+
## How to Contribute 🤝
|
116
113
|
|
117
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/potloc/potlock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/potloc/potlock/blob/main/CODE_OF_CONDUCT.md).
|
118
115
|
|
119
116
|
## License
|
120
117
|
|
@@ -122,4 +119,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
122
119
|
|
123
120
|
## Code of Conduct
|
124
121
|
|
125
|
-
Everyone interacting in the Potlock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
122
|
+
Everyone interacting in the Potlock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/potloc/potlock/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/potlock/client.rb
CHANGED
@@ -37,7 +37,7 @@ module Potlock
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def lock!(&block)
|
40
|
-
lock_manager.lock!(lock_key,
|
40
|
+
lock_manager.lock!(lock_key, retry_delay, &block)
|
41
41
|
end
|
42
42
|
|
43
43
|
def lock_manager
|
@@ -52,6 +52,10 @@ module Potlock
|
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
+
def retry_delay
|
56
|
+
Potlock.configuration.retry_delay * Potlock.configuration.retry_count
|
57
|
+
end
|
58
|
+
|
55
59
|
def redis
|
56
60
|
@redis ||= Redis.new(
|
57
61
|
host: Potlock.configuration.redis_host,
|
data/lib/potlock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: potlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Couraud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redlock
|
@@ -104,7 +104,6 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- ".rspec"
|
106
106
|
- ".rubocop.yml"
|
107
|
-
- ".ruby-version"
|
108
107
|
- CHANGELOG.md
|
109
108
|
- CODE_OF_CONDUCT.md
|
110
109
|
- CONTRIBUTING.md
|
@@ -120,14 +119,14 @@ files:
|
|
120
119
|
- lib/potlock/client.rb
|
121
120
|
- lib/potlock/configuration.rb
|
122
121
|
- lib/potlock/version.rb
|
123
|
-
homepage: https://github.com/
|
122
|
+
homepage: https://github.com/potloc/potlock
|
124
123
|
licenses:
|
125
124
|
- MIT
|
126
125
|
metadata:
|
127
126
|
allowed_push_host: https://rubygems.org
|
128
|
-
changelog_uri: https://github.com/
|
129
|
-
homepage_uri: https://github.com/
|
130
|
-
source_code_uri: https://github.com/
|
127
|
+
changelog_uri: https://github.com/potloc/potlock/CHANGELOG.md
|
128
|
+
homepage_uri: https://github.com/potloc/potlock
|
129
|
+
source_code_uri: https://github.com/potloc/potlock
|
131
130
|
post_install_message:
|
132
131
|
rdoc_options: []
|
133
132
|
require_paths:
|
@@ -136,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
135
|
requirements:
|
137
136
|
- - ">="
|
138
137
|
- !ruby/object:Gem::Version
|
139
|
-
version: 2.
|
138
|
+
version: 2.5.0
|
140
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
140
|
requirements:
|
142
141
|
- - ">="
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.7.4
|