lib/async/redis/cluster_client.rb in async-redis-0.10.1 vs lib/async/redis/cluster_client.rb in async-redis-0.11.0
- old
+ new
@@ -1,13 +1,12 @@
# 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
class ClusterClient
class ReloadError < StandardError
@@ -105,24 +104,24 @@
client = Client.new(endpoint)
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)
end
@@ -191,11 +190,11 @@
# Return Redis::Client for a given key.
# Modified from https://github.com/antirez/redis-rb-cluster/blob/master/cluster.rb#L104-L117
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
return crc16(key) % HASH_SLOTS