Skip to content

Commit a363147

Browse files
committed
Modernize gem.
1 parent 7a0ee0c commit a363147

File tree

13 files changed

+163
-47
lines changed

13 files changed

+163
-47
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Documentation Coverage
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
COVERAGE: PartialSummary
11+
12+
jobs:
13+
validate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: "3.3"
21+
bundler-cache: true
22+
23+
- name: Validate coverage
24+
timeout-minutes: 5
25+
run: bundle exec bake decode:index:coverage lib

.github/workflows/documentation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: bundle exec bake utopia:project:static --force no
4141

4242
- name: Upload documentation artifact
43-
uses: actions/upload-pages-artifact@v2
43+
uses: actions/upload-pages-artifact@v3
4444
with:
4545
path: docs
4646

@@ -55,4 +55,4 @@ jobs:
5555
steps:
5656
- name: Deploy to GitHub Pages
5757
id: deployment
58-
uses: actions/deploy-pages@v3
58+
uses: actions/deploy-pages@v4

.github/workflows/rubocop.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: RuboCop
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: ruby
20+
bundler-cache: true
21+
22+
- name: Run RuboCop
23+
timeout-minutes: 10
24+
run: bundle exec rubocop

.github/workflows/coverage.yaml renamed to .github/workflows/test-coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Coverage
1+
name: Test Coverage
22

33
on: [push, pull_request]
44

@@ -43,7 +43,7 @@ jobs:
4343
- name: Run tests
4444
timeout-minutes: 5
4545
run: bundle exec bake test
46-
46+
4747
- uses: actions/upload-artifact@v3
4848
with:
4949
name: coverage-${{matrix.os}}-${{matrix.ruby}}

.rubocop.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
4+
Layout/IndentationStyle:
5+
Enabled: true
6+
EnforcedStyle: tabs
7+
8+
Layout/InitialIndentation:
9+
Enabled: true
10+
11+
Layout/IndentationWidth:
12+
Enabled: true
13+
Width: 1
14+
15+
Layout/IndentationConsistency:
16+
Enabled: true
17+
EnforcedStyle: normal
18+
19+
Layout/BlockAlignment:
20+
Enabled: true
21+
22+
Layout/EndAlignment:
23+
Enabled: true
24+
EnforcedStyleAlignWith: start_of_line
25+
26+
Layout/BeginEndAlignment:
27+
Enabled: true
28+
EnforcedStyleAlignWith: start_of_line
29+
30+
Layout/ElseAlignment:
31+
Enabled: true
32+
33+
Layout/DefEndAlignment:
34+
Enabled: true
35+
36+
Layout/CaseIndentation:
37+
Enabled: true
38+
39+
Layout/CommentIndentation:
40+
Enabled: true
41+
42+
Layout/EmptyLinesAroundClassBody:
43+
Enabled: true
44+
45+
Layout/EmptyLinesAroundModuleBody:
46+
Enabled: true
47+
48+
Style/FrozenStringLiteralComment:
49+
Enabled: true

async-redis.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
1616
spec.homepage = "https://github.com/socketry/async-redis"
1717

1818
spec.metadata = {
19+
"documentation_uri" => "https://socketry.github.io/async-redis/",
1920
"source_code_uri" => "https://github.com/socketry/async-redis.git",
2021
}
2122

benchmark/performance.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Released under the MIT License.
44
# Copyright, 2019, by Pierre Montelle.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66
# Copyright, 2019, by David Ortiz.
77

88
require 'async/redis'
@@ -25,7 +25,9 @@
2525
key = keys.sample
2626
value = times.to_s
2727

28-
i = 0; while i < times; i += 1
28+
i = 0
29+
while i < times
30+
i += 1
2931
async_client.set(key, value)
3032
end
3133
end
@@ -37,7 +39,9 @@
3739
async_client.pipeline do |pipeline|
3840
sync = pipeline.sync
3941

40-
i = 0; while i < times; i += 1
42+
i = 0
43+
while i < times
44+
i += 1
4145
pipeline.set(key, value)
4246
end
4347
end
@@ -47,7 +51,9 @@
4751
key = keys.sample
4852
value = times.to_s
4953

50-
i = 0; while i < times; i += 1
54+
i = 0
55+
while i < times
56+
i += 1
5157
redis_client.set(key, value)
5258
end
5359
end
@@ -56,7 +62,9 @@
5662
key = keys.sample
5763
value = times.to_s
5864

59-
i = 0; while i < times; i += 1
65+
i = 0
66+
while i < times
67+
i += 1
6068
redis_client_hiredis.set(key, value)
6169
end
6270
end

gems.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2023, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

66
source 'https://rubygems.org'
77

@@ -17,13 +17,16 @@
1717
end
1818

1919
group :test do
20+
gem "sus"
21+
gem "covered"
22+
gem "decode"
23+
gem "rubocop"
24+
2025
gem "bake-test"
2126
gem "bake-test-external"
2227

23-
gem "hiredis"
24-
25-
gem "covered"
26-
27-
gem "sus"
2828
gem "sus-fixtures-async"
29+
30+
gem "redis"
31+
gem "hiredis"
2932
end

lib/async/redis/context/pipeline.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Released under the MIT License.
44
# Copyright, 2019, by David Ortiz.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66
# Copyright, 2022, by Tim Willard.
77

88
require_relative 'generic'
@@ -81,7 +81,7 @@ def collect
8181

8282
def close
8383
flush
84-
ensure
84+
ensure
8585
super
8686
end
8787
end

lib/async/redis/sentinels.rb

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,84 +11,91 @@ module Redis
1111
class SentinelsClient < Client
1212
def initialize(master_name, sentinels, role = :master, protocol = Protocol::RESP2, **options)
1313
@master_name = master_name
14+
1415
@sentinel_endpoints = sentinels.map do |sentinel|
1516
::IO::Endpoint.tcp(sentinel[:host], sentinel[:port])
1617
end
18+
1719
@role = role
18-
1920
@protocol = protocol
2021
@pool = connect(**options)
2122
end
22-
23+
2324
private
24-
25+
2526
# Override the parent method. The only difference is that this one needs
2627
# to resolve the master/slave address.
2728
def connect(**options)
2829
Async::Pool::Controller.wrap(**options) do
2930
endpoint = resolve_address
3031
peer = endpoint.connect
3132
stream = ::IO::Stream(peer)
32-
33+
3334
@protocol.client(stream)
3435
end
3536
end
36-
37+
3738
def resolve_address
38-
address = case @role
39-
when :master then resolve_master
40-
when :slave then resolve_slave
41-
else raise ArgumentError, "Unknown instance role #{@role}"
42-
end
43-
39+
case @role
40+
when :master
41+
resolve_master
42+
when :slave
43+
resolve_slave
44+
else
45+
raise ArgumentError, "Unknown instance role #{@role}"
46+
end => address
47+
4448
address or raise RuntimeError, "Unable to fetch #{@role} via Sentinel."
4549
end
46-
50+
4751
def resolve_master
4852
@sentinel_endpoints.each do |sentinel_endpoint|
4953
client = Client.new(sentinel_endpoint)
50-
54+
5155
begin
5256
address = client.call('sentinel', 'get-master-addr-by-name', @master_name)
5357
rescue Errno::ECONNREFUSED
5458
next
5559
end
56-
60+
5761
return ::IO::Endpoint.tcp(address[0], address[1]) if address
5862
end
59-
63+
6064
nil
6165
end
62-
66+
6367
def resolve_slave
6468
@sentinel_endpoints.each do |sentinel_endpoint|
6569
client = Client.new(sentinel_endpoint)
66-
70+
6771
begin
6872
reply = client.call('sentinel', 'slaves', @master_name)
6973
rescue Errno::ECONNREFUSED
7074
next
7175
end
72-
76+
7377
slaves = available_slaves(reply)
7478
next if slaves.empty?
75-
79+
7680
slave = select_slave(slaves)
7781
return ::IO::Endpoint.tcp(slave['ip'], slave['port'])
7882
end
79-
83+
8084
nil
8185
end
82-
83-
def available_slaves(slaves_cmd_reply)
86+
87+
def available_slaves(reply)
8488
# The reply is an array with the format: [field1, value1, field2,
8589
# value2, etc.].
8690
# When a slave is marked as down by the sentinel, the "flags" field
8791
# (comma-separated array) contains the "s_down" value.
88-
slaves_cmd_reply.map { |s| s.each_slice(2).to_h }
89-
.reject { |s| s.fetch('flags').split(',').include?('s_down') }
92+
slaves = reply.map{|fields| fields.each_slice(2).to_h}
93+
94+
slaves.reject do |slave|
95+
slave['flags'].split(',').include?('s_down')
96+
end
9097
end
91-
98+
9299
def select_slave(available_slaves)
93100
available_slaves.sample
94101
end

0 commit comments

Comments
 (0)