Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 12, 2024
1 parent 63d2ef0 commit 52f83bc
Show file tree
Hide file tree
Showing 43 changed files with 183 additions and 172 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ jobs:
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand Down Expand Up @@ -77,6 +79,8 @@ jobs:

- uses: actions/upload-artifact@v3
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand Down Expand Up @@ -108,6 +112,8 @@ jobs:

- uses: actions/upload-artifact@v3
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand All @@ -125,7 +131,7 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Validate coverage
timeout-minutes: 5
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
8 changes: 4 additions & 4 deletions async-redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Gem::Specification.new do |spec|
spec.version = Async::Redis::VERSION

spec.summary = "A Redis client library."
spec.authors = ["Samuel Williams", "Huba Nagy", "David Ortiz", "Gleb Sinyavskiy", "Mikael Henriksson", "Troex Nevelin", "Alex Matchneer", "Jeremy Jung", "Olle Jonsson", "Pierre Montelle", "Salim Semaoune", "Tim Willard"]
spec.authors = ["Samuel Williams", "Huba Nagy", "David Ortiz", "Gleb Sinyavskiy", "Mikael Henriksson", "Troex Nevelin", "Alex Matchneer", "Jeremy Jung", "Joan Lledó", "Olle Jonsson", "Pierre Montelle", "Salim Semaoune", "Tim Willard"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
spec.signing_key = File.expand_path('~/.gem/release.pem')
spec.cert_chain = ["release.cert"]
spec.signing_key = File.expand_path("~/.gem/release.pem")

spec.homepage = "https://github.com/socketry/async-redis"

Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/async-redis.git",
}

spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
spec.files = Dir.glob(["{lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.1"

Expand Down
4 changes: 2 additions & 2 deletions bake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Copyright, 2018-2023, by Samuel Williams.

def client
require 'irb'
require 'async/redis/client'
require "irb"
require "async/redis/client"

endpoint = Async::Redis.local_endpoint
client = Async::Redis::Client.new(endpoint)
Expand Down
10 changes: 5 additions & 5 deletions benchmark/performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2019, by David Ortiz.

require 'async/redis'
require "async/redis"

require 'redis'
require 'redis/connection/hiredis'
require "redis"
require "redis/connection/hiredis"

require 'benchmark'
require 'benchmark/ips'
require "benchmark"
require "benchmark/ips"

keys = ["X","Y","Z"].freeze
endpoint = Async::Redis.local_endpoint
Expand Down
6 changes: 3 additions & 3 deletions cluster/test/async/redis/cluster_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'async/redis/cluster_client'
require 'sus/fixtures/async'
require 'securerandom'
require "async/redis/cluster_client"
require "sus/fixtures/async"
require "securerandom"

describe Async::Redis::ClusterClient do
include Sus::Fixtures::Async::ReactorContext
Expand Down
2 changes: 1 addition & 1 deletion config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

require 'covered/sus'
require "covered/sus"
include Covered::Sus
2 changes: 1 addition & 1 deletion examples/auth/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.

require_relative '../../lib/async/redis'
require_relative "../../lib/async/redis"

class AuthenticatedRESP2
def initialize(credentials, protocol: Async::Redis::Protocol::RESP2)
Expand Down
8 changes: 4 additions & 4 deletions examples/auth/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright, 2021, by Troex Nevelin.
# Copyright, 2023-2024, by Samuel Williams.

require_relative '../../lib/async/redis'
require_relative "../../lib/async/redis"

# Friendly client wrapper that supports SSL, AUTH and db SELECT
class AsyncRedisClientWrapper
Expand All @@ -13,7 +13,7 @@ class << self
# @param ssl_params [Hash] passed to OpenSSL::SSL::SSLContext
# @param options [Hash] passed to Async::Redis::Client.new
# @return [Async::Redis::Client]
def call(url = 'redis://localhost:6379', ssl_params: nil, **options)
def call(url = "redis://localhost:6379", ssl_params: nil, **options)
uri = URI(url)

endpoint = prepare_endpoint(uri, ssl_params)
Expand All @@ -36,9 +36,9 @@ def call(url = 'redis://localhost:6379', ssl_params: nil, **options)
def prepare_endpoint(uri, ssl_params = nil)
tcp_endpoint = ::IO::Endpoint.tcp(uri.hostname, uri.port)
case uri.scheme
when 'redis'
when "redis"
tcp_endpoint
when 'rediss'
when "rediss"
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.set_params(ssl_params) if ssl_params
::IO::SSLEndpoint.new(tcp_endpoint, ssl_context: ssl_context)
Expand Down
6 changes: 3 additions & 3 deletions examples/redis/pop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'async'
require 'async/barrier'
require 'redis'
require "async"
require "async/barrier"
require "redis"

Async do |parent|
child = Async do |task|
Expand Down
4 changes: 2 additions & 2 deletions examples/redis/pres/pop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'async'
require 'redis'
require "async"
require "redis"

Async do |parent|
child = Async do |task|
Expand Down
6 changes: 3 additions & 3 deletions examples/slow-log/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'set'
require 'async'
require_relative '../../lib/async/redis'
require "set"
require "async"
require_relative "../../lib/async/redis"

endpoint = Async::Redis.local_endpoint(port: 6380)
client = Async::Redis::Client.new(endpoint)
Expand Down
4 changes: 2 additions & 2 deletions examples/slow-log/queues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'async'
require_relative '../../lib/async/redis'
require "async"
require_relative "../../lib/async/redis"

endpoint = Async::Redis.local_endpoint(port: 6380)
client = Async::Redis::Client.new(endpoint)
Expand Down
2 changes: 1 addition & 1 deletion examples/subscribe/pubsub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

require_relative '../../lib/async/redis'
require_relative "../../lib/async/redis"

class Subscription
def initialize(topic, endpoint = Async::Redis.local_endpoint)
Expand Down
10 changes: 5 additions & 5 deletions fixtures/client_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# Copyright, 2018, by Huba Nagy.
# Copyright, 2018-2024, by Samuel Williams.

require 'async/redis'
require 'async/redis/client'
require 'async/redis/key'
require "async/redis"
require "async/redis/client"
require "async/redis/key"

require 'sus/fixtures/async'
require "sus/fixtures/async"

require 'securerandom'
require "securerandom"

ClientContext = Sus::Shared("client context") do
include Sus::Fixtures::Async::ReactorContext
Expand Down
2 changes: 1 addition & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand Down
10 changes: 5 additions & 5 deletions lib/async/redis.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2023, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2020, by David Ortiz.

require_relative 'redis/version'
require_relative 'redis/client'
require_relative "redis/version"
require_relative "redis/client"

require_relative 'redis/cluster_client'
require_relative 'redis/sentinel_client'
require_relative "redis/cluster_client"
require_relative "redis/sentinel_client"
16 changes: 8 additions & 8 deletions lib/async/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# Copyright, 2019, by David Ortiz.
# Copyright, 2020, by Salim Semaoune.

require_relative 'context/pipeline'
require_relative 'context/transaction'
require_relative 'context/subscribe'
require_relative 'endpoint'
require_relative "context/pipeline"
require_relative "context/transaction"
require_relative "context/subscribe"
require_relative "endpoint"

require 'io/endpoint/host_endpoint'
require 'async/pool/controller'
require 'protocol/redis/methods'
require "io/endpoint/host_endpoint"
require "async/pool/controller"
require "protocol/redis/methods"

require 'io/stream'
require "io/stream"

module Async
module Redis
Expand Down
21 changes: 10 additions & 11 deletions lib/async/redis/cluster_client.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2020, by David Ortiz.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2024, by Samuel Williams.

require_relative 'client'
require 'io/stream'
require_relative "client"
require "io/stream"

module Async
module Redis
Expand Down Expand Up @@ -107,20 +106,20 @@ def reload_cluster!(endpoints = @endpoints)
shards = RangeMap.new
endpoints = []

client.call('CLUSTER', 'SHARDS').each do |shard|
client.call("CLUSTER", "SHARDS").each do |shard|
shard = shard.each_slice(2).to_h

slots = shard['slots']
slots = shard["slots"]
range = Range.new(*slots)

nodes = shard['nodes'].map do |node|
nodes = shard["nodes"].map do |node|
node = node.each_slice(2).to_h
endpoint = Endpoint.remote(node['ip'], node['port'])
endpoint = Endpoint.remote(node["ip"], node["port"])

# Collect all endpoints:
endpoints << endpoint

Node.new(node['id'], endpoint, node['role'].to_sym, node['health'].to_sym)
Node.new(node["id"], endpoint, node["role"].to_sym, node["health"].to_sym)
end

shards.add(range, nodes)
Expand Down Expand Up @@ -193,8 +192,8 @@ def crc16(bytes)
def slot_for(key)
key = key.to_s

if s = key.index('{')
if e = key.index('}', s + 1) and e != s + 1
if s = key.index("{")
if e = key.index("}", s + 1) and e != s + 1
key = key[s + 1..e - 1]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/async/redis/context/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright, 2019, by Mikael Henriksson.
# Copyright, 2019-2023, by Samuel Williams.

require 'protocol/redis/methods'
require "protocol/redis/methods"

module Async
module Redis
Expand Down
2 changes: 1 addition & 1 deletion lib/async/redis/context/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2022, by Tim Willard.

require_relative 'generic'
require_relative "generic"

module Async
module Redis
Expand Down
10 changes: 5 additions & 5 deletions lib/async/redis/context/subscribe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

# Released under the MIT License.
# Copyright, 2018, by Huba Nagy.
# Copyright, 2018-2023, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.

require_relative 'generic'
require_relative "generic"

module Async
module Redis
module Context
class Subscribe < Generic
MESSAGE = 'message'
MESSAGE = "message"

def initialize(pool, channels)
super(pool)
Expand Down Expand Up @@ -40,12 +40,12 @@ def each
end

def subscribe(channels)
@connection.write_request ['SUBSCRIBE', *channels]
@connection.write_request ["SUBSCRIBE", *channels]
@connection.flush
end

def unsubscribe(channels)
@connection.write_request ['UNSUBSCRIBE', *channels]
@connection.write_request ["UNSUBSCRIBE", *channels]
@connection.flush
end
end
Expand Down
Loading

0 comments on commit 52f83bc

Please sign in to comment.