redis-cluster-client 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/node.rb +6 -6
- data/lib/redis_client/cluster/node_key.rb +1 -1
- data/lib/redis_client/cluster.rb +43 -30
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7a4668f3eaba9c3053d1464bdf1dc85524e2ba43fdbb2ffbbadc46fb4759d5e6
         | 
| 4 | 
            +
              data.tar.gz: eba5280f698fe559a69cdeba28cef2c0fff87023fa78e7d098042d9cc6c036ac
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 989fd1b82d429ae6450a8c9e1555fc3635c1592c4d68744ad33df9cb26f5d222666fbeb077af99757c6305956936f44b8e38aef405c1a275c10e501559337934
         | 
| 7 | 
            +
              data.tar.gz: c0e88ca74a4d0ff70116969ea0722d1659858587c1cfe8a404edf41658c0b9a87e0f3651db02fe88ad6d099b2948814fcc9415aa793394fb4e75ebc5eef0acec
         | 
| @@ -12,6 +12,8 @@ class RedisClient | |
| 12 12 | 
             
                  SLOT_SIZE = 16_384
         | 
| 13 13 | 
             
                  MIN_SLOT = 0
         | 
| 14 14 | 
             
                  MAX_SLOT = SLOT_SIZE - 1
         | 
| 15 | 
            +
                  IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
         | 
| 16 | 
            +
             | 
| 15 17 | 
             
                  ReloadNeeded = Class.new(::RedisClient::Error)
         | 
| 16 18 |  | 
| 17 19 | 
             
                  class Config < ::RedisClient::Config
         | 
| @@ -127,11 +129,6 @@ class RedisClient | |
| 127 129 | 
             
                    end.values
         | 
| 128 130 | 
             
                  end
         | 
| 129 131 |  | 
| 130 | 
            -
                  # TODO: impl
         | 
| 131 | 
            -
                  def process_all(commands, &block)
         | 
| 132 | 
            -
                    try_map { |_, client| client.process(commands, &block) }.values
         | 
| 133 | 
            -
                  end
         | 
| 134 | 
            -
             | 
| 135 132 | 
             
                  def scale_reading_clients
         | 
| 136 133 | 
             
                    clients = @clients.select do |node_key, _|
         | 
| 137 134 | 
             
                      replica_disabled? ? primary?(node_key) : replica?(node_key)
         | 
| @@ -207,7 +204,10 @@ class RedisClient | |
| 207 204 | 
             
                    options.filter_map do |node_key, option|
         | 
| 208 205 | 
             
                      next if replica_disabled? && replica?(node_key)
         | 
| 209 206 |  | 
| 210 | 
            -
                      config = ::RedisClient::Cluster::Node::Config.new( | 
| 207 | 
            +
                      config = ::RedisClient::Cluster::Node::Config.new(
         | 
| 208 | 
            +
                        scale_read: replica?(node_key),
         | 
| 209 | 
            +
                        **option.merge(kwargs.reject { |k, _| IGNORE_GENERIC_CONFIG_KEYS.include?(k) })
         | 
| 210 | 
            +
                      )
         | 
| 211 211 | 
             
                      client = pool.nil? ? config.new_client : config.new_pool(**pool)
         | 
| 212 212 |  | 
| 213 213 | 
             
                      [node_key, client]
         | 
    
        data/lib/redis_client/cluster.rb
    CHANGED
    
    | @@ -20,19 +20,19 @@ class RedisClient | |
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 22 | 
             
                  def call(*command, **kwargs)
         | 
| 23 | 
            -
                    node_key = @client.send(:find_node_key, command, primary_only: true)
         | 
| 23 | 
            +
                    node_key = @client.send(:find_node_key, *command, primary_only: true)
         | 
| 24 24 | 
             
                    @grouped[node_key] += [[@size, :call, command, kwargs]]
         | 
| 25 25 | 
             
                    @size += 1
         | 
| 26 26 | 
             
                  end
         | 
| 27 27 |  | 
| 28 28 | 
             
                  def call_once(*command, **kwargs)
         | 
| 29 | 
            -
                    node_key = @client.send(:find_node_key, command, primary_only: true)
         | 
| 29 | 
            +
                    node_key = @client.send(:find_node_key, *command, primary_only: true)
         | 
| 30 30 | 
             
                    @grouped[node_key] += [[@size, :call_once, command, kwargs]]
         | 
| 31 31 | 
             
                    @size += 1
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 |  | 
| 34 34 | 
             
                  def blocking_call(timeout, *command, **kwargs)
         | 
| 35 | 
            -
                    node_key = @client.send(:find_node_key, command, primary_only: true)
         | 
| 35 | 
            +
                    node_key = @client.send(:find_node_key, *command, primary_only: true)
         | 
| 36 36 | 
             
                    @grouped[node_key] += [[@size, :blocking_call, timeout, command, kwargs]]
         | 
| 37 37 | 
             
                    @size += 1
         | 
| 38 38 | 
             
                  end
         | 
| @@ -65,7 +65,37 @@ class RedisClient | |
| 65 65 | 
             
                  end
         | 
| 66 66 | 
             
                end
         | 
| 67 67 |  | 
| 68 | 
            +
                class PubSub
         | 
| 69 | 
            +
                  def initialize(client)
         | 
| 70 | 
            +
                    @client = client
         | 
| 71 | 
            +
                    @pubsub = nil
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  def call(*command, **kwargs)
         | 
| 75 | 
            +
                    close
         | 
| 76 | 
            +
                    @pubsub = @client.send(:assign_node, *command).pubsub
         | 
| 77 | 
            +
                    @pubsub.call(*command, **kwargs)
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  def close
         | 
| 81 | 
            +
                    @pubsub&.close
         | 
| 82 | 
            +
                    @pubsub = nil
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                  def next_event(timeout = nil)
         | 
| 86 | 
            +
                    @pubsub&.next_event(timeout)
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
             | 
| 68 90 | 
             
                ZERO_CURSOR_FOR_SCAN = '0'
         | 
| 91 | 
            +
                CMD_SCAN = 'SCAN'
         | 
| 92 | 
            +
                CMD_SSCAN = 'SSCAN'
         | 
| 93 | 
            +
                CMD_HSCAN = 'HSCAN'
         | 
| 94 | 
            +
                CMD_ZSCAN = 'ZSCAN'
         | 
| 95 | 
            +
                CMD_ASKING = 'ASKING'
         | 
| 96 | 
            +
                REPLY_OK = 'OK'
         | 
| 97 | 
            +
                REPLY_MOVED = 'MOVED'
         | 
| 98 | 
            +
                REPLY_ASK = 'ASK'
         | 
| 69 99 |  | 
| 70 100 | 
             
                def initialize(config, pool: nil, **kwargs)
         | 
| 71 101 | 
             
                  @config = config.dup
         | 
| @@ -97,35 +127,27 @@ class RedisClient | |
| 97 127 |  | 
| 98 128 | 
             
                  cursor = ZERO_CURSOR_FOR_SCAN
         | 
| 99 129 | 
             
                  loop do
         | 
| 100 | 
            -
                    cursor, keys = _scan( | 
| 130 | 
            +
                    cursor, keys = _scan(CMD_SCAN, cursor, *args, **kwargs)
         | 
| 101 131 | 
             
                    keys.each(&block)
         | 
| 102 132 | 
             
                    break if cursor == ZERO_CURSOR_FOR_SCAN
         | 
| 103 133 | 
             
                  end
         | 
| 104 134 | 
             
                end
         | 
| 105 135 |  | 
| 106 136 | 
             
                def sscan(key, *args, **kwargs, &block)
         | 
| 107 | 
            -
                  node = assign_node( | 
| 137 | 
            +
                  node = assign_node(CMD_SSCAN, key)
         | 
| 108 138 | 
             
                  try_send(node, :sscan, key, *args, **kwargs, &block)
         | 
| 109 139 | 
             
                end
         | 
| 110 140 |  | 
| 111 141 | 
             
                def hscan(key, *args, **kwargs, &block)
         | 
| 112 | 
            -
                  node = assign_node( | 
| 142 | 
            +
                  node = assign_node(CMD_HSCAN, key)
         | 
| 113 143 | 
             
                  try_send(node, :hscan, key, *args, **kwargs, &block)
         | 
| 114 144 | 
             
                end
         | 
| 115 145 |  | 
| 116 146 | 
             
                def zscan(key, *args, **kwargs, &block)
         | 
| 117 | 
            -
                  node = assign_node( | 
| 147 | 
            +
                  node = assign_node(CMD_ZSCAN, key)
         | 
| 118 148 | 
             
                  try_send(node, :zscan, key, *args, **kwargs, &block)
         | 
| 119 149 | 
             
                end
         | 
| 120 150 |  | 
| 121 | 
            -
                def mset
         | 
| 122 | 
            -
                  # TODO: impl
         | 
| 123 | 
            -
                end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                def mget
         | 
| 126 | 
            -
                  # TODO: impl
         | 
| 127 | 
            -
                end
         | 
| 128 | 
            -
             | 
| 129 151 | 
             
                def pipelined
         | 
| 130 152 | 
             
                  pipeline = ::RedisClient::Cluster::Pipeline.new(self)
         | 
| 131 153 | 
             
                  yield pipeline
         | 
| @@ -135,17 +157,8 @@ class RedisClient | |
| 135 157 | 
             
                end
         | 
| 136 158 |  | 
| 137 159 | 
             
                def pubsub
         | 
| 138 | 
            -
                   | 
| 139 | 
            -
                end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                def size
         | 
| 142 | 
            -
                  # TODO: impl
         | 
| 143 | 
            -
                end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
                def with(options = {})
         | 
| 146 | 
            -
                  # TODO: impl
         | 
| 160 | 
            +
                  ::RedisClient::Cluster::PubSub.new(self)
         | 
| 147 161 | 
             
                end
         | 
| 148 | 
            -
                alias then with
         | 
| 149 162 |  | 
| 150 163 | 
             
                def close
         | 
| 151 164 | 
             
                  @node.each(&:close)
         | 
| @@ -253,17 +266,17 @@ class RedisClient | |
| 253 266 | 
             
                def try_send(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
         | 
| 254 267 | 
             
                  node.send(method, *args, **kwargs, &block)
         | 
| 255 268 | 
             
                rescue ::RedisClient::CommandError => e
         | 
| 256 | 
            -
                  if e.message.start_with?( | 
| 269 | 
            +
                  if e.message.start_with?(REPLY_MOVED)
         | 
| 257 270 | 
             
                    raise if retry_count <= 0
         | 
| 258 271 |  | 
| 259 272 | 
             
                    node = assign_redirection_node(e.message)
         | 
| 260 273 | 
             
                    retry_count -= 1
         | 
| 261 274 | 
             
                    retry
         | 
| 262 | 
            -
                  elsif e.message.start_with?( | 
| 275 | 
            +
                  elsif e.message.start_with?(REPLY_ASK)
         | 
| 263 276 | 
             
                    raise if retry_count <= 0
         | 
| 264 277 |  | 
| 265 278 | 
             
                    node = assign_asking_node(e.message)
         | 
| 266 | 
            -
                    node.call( | 
| 279 | 
            +
                    node.call(CMD_ASKING)
         | 
| 267 280 | 
             
                    retry_count -= 1
         | 
| 268 281 | 
             
                    retry
         | 
| 269 282 | 
             
                  else
         | 
| @@ -309,11 +322,11 @@ class RedisClient | |
| 309 322 | 
             
                end
         | 
| 310 323 |  | 
| 311 324 | 
             
                def assign_node(*command)
         | 
| 312 | 
            -
                  node_key = find_node_key(command)
         | 
| 325 | 
            +
                  node_key = find_node_key(*command)
         | 
| 313 326 | 
             
                  find_node(node_key)
         | 
| 314 327 | 
             
                end
         | 
| 315 328 |  | 
| 316 | 
            -
                def find_node_key(command, primary_only: false)
         | 
| 329 | 
            +
                def find_node_key(*command, primary_only: false)
         | 
| 317 330 | 
             
                  key = @command.extract_first_key(command)
         | 
| 318 331 | 
             
                  return if key.empty?
         | 
| 319 332 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: redis-cluster-client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Taishi Kasuga
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-06- | 
| 11 | 
            +
            date: 2022-06-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: redis-client
         |