renoir 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c38bafe64d4e6e17eb9e8ac7bfda4518a16831f
4
- data.tar.gz: 934d5766ccfa78fe3d7113f937ced20a2d9e1ae5
3
+ metadata.gz: fcf83e530a5859d415a1bbe367fcb3505f5ec96e
4
+ data.tar.gz: c06b4040a3d4639547d5ee7d9570b8009dd2babd
5
5
  SHA512:
6
- metadata.gz: 29202c8ae95394db795908d472645f1134c04a50ead0833c6fd7c7348e3b251b4f9a9f2f12d0e91f621c041cd379430fdd0cb81e920f77467a103f629a6b73a5
7
- data.tar.gz: 2521e02fd50177c9e2a380eb5025122177964d1d708ed4b2693873d417ec96771c27653a77271a326f4bae11b8aa9e956252dae49cce8c8c7ee0f113de89f07a
6
+ metadata.gz: 4cf573b2c5af35650da61f303f77e6b95d6aa42c29c547d4c5122123cbe4c1aad38c7f730d2e598b7e2c5130cc885b5033fddda5e77363cdf938ad2d943b3db1
7
+ data.tar.gz: a85045df90e31e5bab6e5685b231ae7d5e726b69ab788f08aa1c034308024064b49f32b4b0dfa4840f0175e8f52c3de35439dbe579bacbe25fb0bc731faf393d
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown -M redcarpet --no-private
data/lib/renoir.rb CHANGED
@@ -2,9 +2,11 @@ require "renoir/version"
2
2
  require "renoir/client"
3
3
 
4
4
  module Renoir
5
+ # Base class of Renoir errors.
5
6
  class BaseError < RuntimeError
6
7
  end
7
8
 
9
+ # Error related to redirection.
8
10
  class RedirectionError < BaseError
9
11
  end
10
12
  end
data/lib/renoir/client.rb CHANGED
@@ -19,6 +19,20 @@ module Renoir
19
19
  connection_adapter: :redis,
20
20
  }.freeze
21
21
 
22
+ # @option options [Array<String, Array<String, Fixnum>, Hash{String => Fixnum}>] :cluster_nodes
23
+ # Array of hostnames and ports of cluster nodes. At least one node must be specified.
24
+ # An element could be one of: `String` (`"127.0.0.1:6379"`), `Array` (`["127.0.0.1", 6379]`) or
25
+ # `Hash` (`{ host: "127.0.0.1", port: 6379 }`).
26
+ # Defaults to `[["127.0.0.1", 6379]]`.
27
+ # @option options [Fixnum] :max_redirection Max number of MOVED/ASK redirections. Defaults to `10`.
28
+ # @option options [Fixnum] :max_connection_error
29
+ # Max number of reconnections for connection errors. Defaults to `5`.
30
+ # @option options [Float] :connect_retry_random_factor A factor of reconnection interval. Defaults to `0.1`.
31
+ # @option options [Float] :connect_retry_interval
32
+ # A base interval (seconds) of reconnection. Defaults to `0.001`, i.e., 1 ms.
33
+ # @option options [String, Symbol] :connection_adapter
34
+ # Adapter name of a connection used by client. Defaults to `:redis`.
35
+ # @option options [Logger] :logger A logger. Defaults to `nil`.
22
36
  def initialize(options)
23
37
  @connections = {}
24
38
  @cluster_info = ClusterInfo.new
@@ -50,10 +64,22 @@ module Renoir
50
64
  @refresh_slots_mutex = Mutex.new
51
65
  end
52
66
 
67
+ # Call EVAL command.
68
+ #
69
+ # @param [Array] args arguments of EVAL passed to a connection backend
70
+ # @yield [Object] a connection backend may yield
71
+ # @raise [Renoir::RedirectionError] when too many redirections
72
+ # @return the value returned by a connection backend
53
73
  def eval(*args, &block)
54
74
  call(:eval, *args, &block)
55
75
  end
56
76
 
77
+ # Pipeline commands and call them with MULTI/EXEC.
78
+ #
79
+ # @yield [Renoir::Pipeline] A command pipeliner which has almost compatible interfaces with {Renoir::Client}.
80
+ # @return the value returned by a connection backend
81
+ # @raise [Renoir::RedirectionError] when too many redirections
82
+ # @note Return value of {Renoir::Pipeline} methods is useless since "future variable" is not yet supported.
57
83
  def multi(&block)
58
84
  commands = pipeline_commands(&block)
59
85
  slot = get_slot_from_commands(commands)
@@ -62,6 +88,12 @@ module Renoir
62
88
  call_with_redirection(slot, [[:multi]] + commands + [[:exec]])
63
89
  end
64
90
 
91
+ # Pipeline commands and call them.
92
+ #
93
+ # @yield [Renoir::Pipeline] A command pipeliner which has almost compatible interfaces with {Renoir::Client}.
94
+ # @return the value returned by a connection backend
95
+ # @raise [Renoir::RedirectionError] when too many redirections
96
+ # @note Return value of {Renoir::Pipeline} methods is useless since "future variable" is not yet supported.
65
97
  def pipelined(&block)
66
98
  commands = pipeline_commands(&block)
67
99
  slot = get_slot_from_commands(commands)
@@ -70,6 +102,12 @@ module Renoir
70
102
  call_with_redirection(slot, commands)
71
103
  end
72
104
 
105
+ # Call a Redis command.
106
+ #
107
+ # @param [Array] command a Redis command passed to a connection backend
108
+ # @yield [Object] a connection backend may yield
109
+ # @return the value returned by a connection backend
110
+ # @raise [Renoir::RedirectionError] when too many redirections
73
111
  def call(*command, &block)
74
112
  slot = get_slot_from_commands([command])
75
113
 
@@ -77,15 +115,21 @@ module Renoir
77
115
  call_with_redirection(slot, [command], &block)[0]
78
116
  end
79
117
 
118
+ # Close all holding connections.
80
119
  def close
81
120
  while entry = @connections.shift
82
121
  entry[1].close
83
122
  end
84
123
  end
85
124
 
125
+ # Enumerate connections of cluster nodes.
126
+ #
127
+ # @yield [Object] an connection instance of connection backend
128
+ # @return [Enumerable]
86
129
  def each_node
87
130
  return enum_for(:each_node) unless block_given?
88
131
 
132
+ refresh_slots
89
133
  @cluster_info.nodes.each do |node|
90
134
  fetch_connection(node).with_raw_connection do |conn|
91
135
  yield conn
@@ -93,6 +137,7 @@ module Renoir
93
137
  end
94
138
  end
95
139
 
140
+ # Delegated to {#call}.
96
141
  def method_missing(command, *args, &block)
97
142
  call(command, *args, &block)
98
143
  end
@@ -1,4 +1,5 @@
1
1
  module Renoir
2
+ # Store cluster information.
2
3
  class ClusterInfo
3
4
  class << self
4
5
  def node_name(host, port)
@@ -1,6 +1,8 @@
1
1
  require "renoir/connection_adapters/reply"
2
2
 
3
3
  module Renoir
4
+ # Adapter of backend Redis connection. {Renoir::Client} communicates with a
5
+ # backend connection through a corresponding adapter.
4
6
  module ConnectionAdapters
5
7
  autoload :Redis, "renoir/connection_adapters/redis"
6
8
  end
@@ -1,20 +1,34 @@
1
1
  module Renoir
2
2
  module ConnectionAdapters
3
+ # Abstract class.
3
4
  class Base
4
5
  class << self
6
+ # Return keys in a `command`.
7
+ #
8
+ # @param [Array] command a command argument
9
+ # @return [Array<String>] keys
5
10
  def get_keys_from_command(command)
6
11
  fail "a connection adapter must override #get_keys_from_command"
7
12
  end
8
13
  end
9
14
 
15
+ # Call pipelined commands.
16
+ #
17
+ # @param [Array<Array>] commands list of commands.
18
+ # @param [Boolean] asking Call ASKING command at first if `true`
19
+ # @yield [Object] a connection backend may yield
10
20
  def call(commands, asking=false, &block)
11
21
  fail "a connection adapter must override #call"
12
22
  end
13
23
 
24
+ # Close a backend connection.
14
25
  def close
15
26
  fail "a connection adapter must override #close"
16
27
  end
17
28
 
29
+ # Return a backend connection.
30
+ #
31
+ # @return [Object] a backend connection instance
18
32
  def with_raw_connection
19
33
  fail "a connection adapter must override #with_raw_connection"
20
34
  end
@@ -3,6 +3,7 @@ require "renoir/connection_adapters/base"
3
3
 
4
4
  module Renoir
5
5
  module ConnectionAdapters
6
+ # Connection adapter for {https://rubygems.org/gems/redis}.
6
7
  class Redis < Base
7
8
  class << self
8
9
  def get_keys_from_command(command)
@@ -1,5 +1,6 @@
1
1
  module Renoir
2
2
  module ConnectionAdapters
3
+ # Reply for {Renoir::Client}.
3
4
  module Reply
4
5
  class Base
5
6
  attr_reader :cause
data/lib/renoir/crc16.rb CHANGED
@@ -1,18 +1,18 @@
1
- # This is the CRC16 algorithm used by Redis Cluster to hash keys.
2
- # Implementation according to CCITT standards.
3
- #
4
- # This is actually the XMODEM CRC 16 algorithm, using the
5
- # following parameters:
6
- #
7
- # Name : "XMODEM", also known as "ZMODEM", "CRC-16/ACORN"
8
- # Width : 16 bit
9
- # Poly : 1021 (That is actually x^16 + x^12 + x^5 + 1)
10
- # Initialization : 0000
11
- # Reflect Input byte : False
12
- # Reflect Output CRC : False
13
- # Xor constant to output CRC : 0000
14
- # Output for "123456789" : 31C3
15
1
  module Renoir
2
+ # This is the CRC16 algorithm used by Redis Cluster to hash keys.
3
+ # Implementation according to CCITT standards.
4
+ #
5
+ # This is actually the XMODEM CRC 16 algorithm, using the
6
+ # following parameters:
7
+ #
8
+ # - Name : "XMODEM", also known as "ZMODEM", "CRC-16/ACORN"
9
+ # - Width : 16 bit
10
+ # - Poly : 1021 (That is actually x^16 + x^12 + x^5 + 1)
11
+ # - Initialization : 0000
12
+ # - Reflect Input byte : False
13
+ # - Reflect Output CRC : False
14
+ # - Xor constant to output CRC : 0000
15
+ # - Output for "123456789" : 31C3
16
16
  module CRC16
17
17
  def self.crc16(bytes)
18
18
  crc = 0
@@ -6,14 +6,19 @@ module Renoir
6
6
  @commands = []
7
7
  end
8
8
 
9
+ # Delegated to {#call}.
9
10
  def eval(*args)
10
11
  call(:eval, *args)
11
12
  end
12
13
 
14
+ # Store a command for pipelining.
15
+ #
16
+ # @param [Array] a Redis command passed to a connection backend
13
17
  def call(*command)
14
18
  @commands << command
15
19
  end
16
20
 
21
+ # Delegated to {#call}.
17
22
  def method_missing(command, *args, &block)
18
23
  call(command, *args, &block)
19
24
  end
@@ -1,3 +1,3 @@
1
1
  module Renoir
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renoir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Saito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - ".yardopts"
78
79
  - CODE_OF_CONDUCT.md
79
80
  - Gemfile
80
81
  - LICENSE.txt