Skip to content

Commit 605b399

Browse files
authored
cluster support - v0.1.2 (#5)
* cluster support * Linting cleanup * fixes specs * which => command -v * try installing redis manually * redis service cleanup and server shutdown * benchmark workflow should be good * cluster client builder specs * don't build the cluster client if not retrying * typo * better comments and cleaner nodes method
1 parent 1bfda74 commit 605b399

23 files changed

+506
-51
lines changed

.github/workflows/benchmark.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,40 @@
44
name: CI Benchmark Test
55
on: [pull_request]
66
jobs:
7-
test:
7+
benchmark:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
1111
ruby:
1212
- '3.2.0'
13-
services:
14-
redis:
15-
image: redis
16-
ports: ["6379:6379"]
1713
steps:
1814
- uses: actions/checkout@v4
1915
- uses: ruby/setup-ruby@v1
2016
with:
2117
ruby-version: ${{ matrix.ruby }}
2218
bundler-cache: true
19+
- name: Install redis
20+
run: sudo apt-get install -y redis-tools redis-server
21+
22+
- name: Verify that redis is up
23+
run: redis-cli ping
24+
25+
- name: Shut primary redis down
26+
run: sudo systemctl stop redis
27+
28+
- name: Start redis cluster
29+
run: bin/cluster start
30+
31+
- name: Create redis cluster
32+
run: bin/cluster create -f
33+
2334
- name: Run benchmark tests
2435
run: bundle exec ruby benchmark.rb
36+
env:
37+
WORKFLOW_PORT: 30001
38+
39+
- name: Stop redis cluster
40+
run: bin/cluster stop
41+
42+
- name: Clean redis cluster
43+
run: bin/cluster clean

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name: CI Ruby Gem Build
55
on: [pull_request]
66
jobs:
7-
gem-build:
7+
build:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:

.github/workflows/codeql.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name: CI CodeQL Analysis
55
on: [pull_request]
66
jobs:
7-
analyze:
8-
name: Analyze
7+
codeql:
98
runs-on: ubuntu-latest
109
permissions:
1110
actions: read
@@ -21,6 +20,6 @@ jobs:
2120
- name: Initialize CodeQL
2221
uses: github/codeql-action/init@v3
2322
with:
24-
languages: ${{matrix.language}}
23+
languages: ${{ matrix.language }}
2524
- name: Perform CodeQL Analysis
2625
uses: github/codeql-action/analyze@v3

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- '*'
99
workflow_dispatch:
1010
jobs:
11-
gem-publish:
11+
publish:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4

.github/workflows/rspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name: CI RSpec Tests
55
on: [pull_request]
66
jobs:
7-
test:
7+
rspec:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:

.github/workflows/rubocop.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
name: CI Rubocop Linting
55
on: [pull_request]
66
jobs:
7-
build:
7+
rubocop:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
1111
ruby:
1212
- '3.2.0'
13-
# steps:
14-
# - uses: actions/checkout@v2
15-
# - name: Rubocop Linter Action
16-
# uses: andrewmcodes/rubocop-linter-action@v3.3.0
17-
# env:
18-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1913
steps:
2014
- uses: actions/checkout@v4
2115
- uses: ruby/setup-ruby@v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# compiled gems
1414
*.gem
15+
16+
# cluster stuff
17+
bin/.cluster_dump/

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ RSpec/MultipleExpectations:
4040

4141
# Example has too many lines. [8/5]
4242
RSpec/ExampleLength:
43-
Max: 10
43+
Max: 20

Gemfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
PATH
22
remote: .
33
specs:
4-
redis-single-file (0.1.1)
4+
redis-single-file (0.1.2)
55
redis (~> 5.3.0)
6+
redis-clustering (~> 5.3.0)
67

78
GEM
89
remote: https://rubygems.org/
@@ -32,6 +33,11 @@ GEM
3233
redis-client (>= 0.22.0)
3334
redis-client (0.23.2)
3435
connection_pool
36+
redis-cluster-client (0.13.3)
37+
redis-client (~> 0.22)
38+
redis-clustering (5.3.0)
39+
redis (= 5.3.0)
40+
redis-cluster-client (>= 0.10.0)
3541
regexp_parser (2.10.0)
3642
rspec (3.13.0)
3743
rspec-core (~> 3.13.0)

benchmark.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
require 'benchmark/ips'
44
require 'redis_single_file'
55

6-
scenario_1_semaphore = RedisSingleFile.new(name: :scenario1)
7-
scenario_2_semaphore = RedisSingleFile.new(name: :scenario2)
6+
PORT = ENV['WORKFLOW_PORT'] || 6379
7+
8+
scenario_1_semaphore = RedisSingleFile.new(name: :scenario1, port: PORT)
9+
scenario_2_semaphore = RedisSingleFile.new(name: :scenario2, port: PORT)
810

911
Benchmark.ips do |x|
1012
x.report('synchronize') do
@@ -18,18 +20,18 @@
1820
x.report('threaded (10x)') do
1921
threads = 10.times.map do
2022
Thread.new do
21-
scenario_3_semaphore = RedisSingleFile.new(name: :scenario3)
23+
scenario_3_semaphore = RedisSingleFile.new(name: :scenario3, port: PORT)
2224
scenario_3_semaphore.synchronize { nil }
2325
end
2426
end
2527

26-
threads.each { _1.join(0.05) } while threads.any?(&:alive?)
28+
threads.each { _1.join(0.2) } while threads.any?(&:alive?)
2729
end
2830

2931
x.report('forked (10x)') do
3032
10.times.each do
3133
fork do
32-
scenario_4_semaphore = RedisSingleFile.new(name: :scenario4)
34+
scenario_4_semaphore = RedisSingleFile.new(name: :scenario4, port: PORT)
3335
scenario_4_semaphore.synchronize { nil }
3436
end
3537
end

0 commit comments

Comments
 (0)