redis-key_hash 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7dd84fcafb7fdfa166839a664d177a851ad7bf5
4
- data.tar.gz: 496ced31fb42c55927fc739c6e5a930f6ea046f2
3
+ metadata.gz: 1ebc31ea112f09f727db862ad79e060886d899a1
4
+ data.tar.gz: 346eec6148ba5d648b4ebac19f3d0b4d478841e8
5
5
  SHA512:
6
- metadata.gz: 9aa7190e2b7e7f50651d8628a1b7488e864f4a11cb803f25553f2233480f37f97af38024a335502dc93e3a7c7b3d2d451676b50399b81e40ff1d75e210a0487c
7
- data.tar.gz: 7356c4f3ecb5efe65b4c8e8fff4bc67d70da7cc4560974d06736dad5f1a171a9bbb80307dfc7f373dee23af6cbc9e8daace89ad53c5d2fa7890ea260756f05c7
6
+ metadata.gz: 603fbb62409fa053c9cdcff1bb0fcbfad08c21371d1fc1f5256a6f4063d3a7119d310c52cf3a1861689c2ac69cddabaf93a983e49be80af484a7767a0bcbfb21
7
+ data.tar.gz: d72e817eb421afe8bbee7c48c1fed69af91d497d8c91254d38925beb58e12cd69453b8082fc0147c3c99221c15d6d11495aecd6b95518c0457ae71b2a3d5920b
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
- *.gem
3
2
  *.rbc
4
3
  /.config
5
4
  /coverage/
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ AllCops:
3
+ Include:
4
+ - Rakefile
5
+ - Gemfile
6
+ - '*.gemspec'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,214 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-08-29 14:52:28 -0700 using RuboCop version 0.49.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
12
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
13
+ Layout/EmptyLinesAroundClassBody:
14
+ Exclude:
15
+ - 'test/redis/key_hash_test.rb'
16
+
17
+ # Offense count: 4
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
20
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
21
+ Layout/EmptyLinesAroundModuleBody:
22
+ Exclude:
23
+ - 'lib/redis/key_hash.rb'
24
+
25
+ # Offense count: 273
26
+ # Cop supports --auto-correct.
27
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
28
+ Layout/ExtraSpacing:
29
+ Exclude:
30
+ - 'lib/redis/key_hash.rb'
31
+ - 'test/redis/key_hash_test.rb'
32
+
33
+ # Offense count: 290
34
+ # Cop supports --auto-correct.
35
+ Layout/SpaceAfterComma:
36
+ Exclude:
37
+ - 'lib/redis/key_hash.rb'
38
+ - 'test/redis/key_hash_test.rb'
39
+
40
+ # Offense count: 7
41
+ # Cop supports --auto-correct.
42
+ # Configuration parameters: AllowForAlignment.
43
+ Layout/SpaceAroundOperators:
44
+ Exclude:
45
+ - 'lib/redis/key_hash.rb'
46
+ - 'test/redis/key_hash_test.rb'
47
+
48
+ # Offense count: 104
49
+ # Cop supports --auto-correct.
50
+ Layout/SpaceInsideBrackets:
51
+ Exclude:
52
+ - 'lib/redis/key_hash.rb'
53
+ - 'test/redis/key_hash_test.rb'
54
+
55
+ # Offense count: 1
56
+ Lint/UselessAssignment:
57
+ Exclude:
58
+ - 'lib/redis/key_hash.rb'
59
+
60
+ # Offense count: 2
61
+ Metrics/AbcSize:
62
+ Max: 31
63
+
64
+ # Offense count: 1
65
+ # Configuration parameters: CountComments.
66
+ Metrics/ClassLength:
67
+ Max: 2228
68
+
69
+ # Offense count: 9
70
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
71
+ # URISchemes: http, https
72
+ Metrics/LineLength:
73
+ Max: 82
74
+
75
+ # Offense count: 3
76
+ # Configuration parameters: CountComments.
77
+ Metrics/MethodLength:
78
+ Max: 35
79
+
80
+ # Offense count: 1
81
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
82
+ # SupportedStyles: nested, compact
83
+ Style/ClassAndModuleChildren:
84
+ Exclude:
85
+ - 'lib/redis/key_hash.rb'
86
+
87
+ # Offense count: 2
88
+ Style/Documentation:
89
+ Exclude:
90
+ - 'spec/**/*'
91
+ - 'test/**/*'
92
+ - 'lib/redis/key_hash.rb'
93
+
94
+ # Offense count: 1
95
+ # Cop supports --auto-correct.
96
+ Style/EmptyLiteral:
97
+ Exclude:
98
+ - 'lib/redis/key_hash.rb'
99
+
100
+ # Offense count: 3
101
+ # Cop supports --auto-correct.
102
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
103
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
104
+ Style/HashSyntax:
105
+ Exclude:
106
+ - 'Rakefile'
107
+ - 'lib/redis/key_hash.rb'
108
+
109
+ # Offense count: 1
110
+ # Cop supports --auto-correct.
111
+ # Configuration parameters: MaxLineLength.
112
+ Style/IfUnlessModifier:
113
+ Exclude:
114
+ - 'lib/redis/key_hash.rb'
115
+
116
+ # Offense count: 1
117
+ # Configuration parameters: SupportedStyles.
118
+ # SupportedStyles: snake_case, camelCase
119
+ Style/MethodName:
120
+ EnforcedStyle: snake_case
121
+
122
+ # Offense count: 1
123
+ # Cop supports --auto-correct.
124
+ Style/MutableConstant:
125
+ Exclude:
126
+ - 'lib/redis/key_hash/version.rb'
127
+
128
+ # Offense count: 1
129
+ # Cop supports --auto-correct.
130
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
131
+ # SupportedStyles: both, prefix, postfix
132
+ Style/NegatedIf:
133
+ Exclude:
134
+ - 'lib/redis/key_hash.rb'
135
+
136
+ # Offense count: 10
137
+ # Cop supports --auto-correct.
138
+ # Configuration parameters: Strict.
139
+ Style/NumericLiterals:
140
+ MinDigits: 6
141
+
142
+ # Offense count: 1
143
+ # Cop supports --auto-correct.
144
+ # Configuration parameters: PreferredDelimiters.
145
+ Style/PercentLiteralDelimiters:
146
+ Exclude:
147
+ - 'redis-key_hash.gemspec'
148
+
149
+ # Offense count: 1
150
+ # Cop supports --auto-correct.
151
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
152
+ # SupportedStyles: short, verbose
153
+ Style/PreferredHashMethods:
154
+ Exclude:
155
+ - 'lib/redis/key_hash.rb'
156
+
157
+ # Offense count: 1
158
+ # Cop supports --auto-correct.
159
+ Style/RedundantBegin:
160
+ Exclude:
161
+ - 'lib/redis/key_hash.rb'
162
+
163
+ # Offense count: 1
164
+ # Cop supports --auto-correct.
165
+ # Configuration parameters: AllowMultipleReturnValues.
166
+ Style/RedundantReturn:
167
+ Exclude:
168
+ - 'lib/redis/key_hash.rb'
169
+
170
+ # Offense count: 16410
171
+ # Cop supports --auto-correct.
172
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
173
+ # SupportedStyles: single_quotes, double_quotes
174
+ Style/StringLiterals:
175
+ Exclude:
176
+ - 'Rakefile'
177
+ - 'bin/console'
178
+ - 'lib/redis/key_hash.rb'
179
+ - 'redis-key_hash.gemspec'
180
+ - 'test/redis/key_hash_test.rb'
181
+
182
+ # Offense count: 1
183
+ # Cop supports --auto-correct.
184
+ # Configuration parameters: MinSize, SupportedStyles.
185
+ # SupportedStyles: percent, brackets
186
+ Style/SymbolArray:
187
+ EnforcedStyle: brackets
188
+
189
+ # Offense count: 3
190
+ # Cop supports --auto-correct.
191
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
192
+ # SupportedStylesForMultiline: comma, consistent_comma, no_comma
193
+ Style/TrailingCommaInLiteral:
194
+ Exclude:
195
+ - 'test/redis/key_hash_test.rb'
196
+
197
+ # Offense count: 7
198
+ # Cop supports --auto-correct.
199
+ # Configuration parameters: SupportedStyles, MinSize, WordRegex.
200
+ # SupportedStyles: percent, brackets
201
+ Style/WordArray:
202
+ EnforcedStyle: brackets
203
+
204
+ # Offense count: 1
205
+ # Cop supports --auto-correct.
206
+ Style/YodaCondition:
207
+ Exclude:
208
+ - 'lib/redis/key_hash.rb'
209
+
210
+ # Offense count: 1
211
+ # Cop supports --auto-correct.
212
+ Style/ZeroLengthPredicate:
213
+ Exclude:
214
+ - 'lib/redis/key_hash.rb'
data/.travis.yml CHANGED
@@ -1,5 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ before_install:
4
+ - gem install bundler -v 1.14.6
5
+ - gem install rubocop
3
6
  rvm:
4
7
  - 2.1.6
5
- before_install: gem install bundler -v 1.14.6
8
+ script:
9
+ - rubocop
10
+ - rake test
data/README.md CHANGED
@@ -1,7 +1,24 @@
1
- # Redis::KeyHash
2
-
3
- Tests of key hash slot agreement for use with Redis Cluster and
4
- RedisLabs Enterprise Cluster.
1
+ # Redis::KeyHash ![TravisCI](https://travis-ci.org/ProsperWorks/redis-key_hash.svg?branch=master)
2
+
3
+ redis-key_hash provides tests of key hash slot agreement for use with
4
+ Redis Cluster and RedisLabs Enterprise Cluster.
5
+
6
+ Redis Cluster (RC) and RedisLabs Enterprise Cluster (RLEC) both
7
+ require that all keys in multi-key operations hash to the same node.
8
+ They use slightly different default hashing algorithms and RLEC offers
9
+ customizable hash pattersn.
10
+
11
+ It is impossible to predict which nodes will host each shard, and
12
+ difficult to predict which slot will host each key. But it is easy to
13
+ identify the key hash tag which RC or RLEC will use to select a shard.
14
+ Where key hash tags agree, we can be certain that slots and nodes will
15
+ also agree - even if hash tag disagreement does not always imply slot
16
+ or node disagreement.
17
+
18
+ By pulling this check into Ruby we can arrange to fail fast, before
19
+ sending a command to Redis which is at risk of CROSSLOT failure. We
20
+ can also validate key management schemes in unit tests which run
21
+ without support services or with a non-sharded Redis.
5
22
 
6
23
  ## Installation
7
24
 
@@ -5,8 +5,6 @@
5
5
  #
6
6
  # (error) CROSSSLOT Keys in request don't hash to the same slot
7
7
  #
8
- # TODO: rubocop
9
- #
10
8
  # TODO: rdoc
11
9
  #
12
10
  class Redis
@@ -8,13 +8,33 @@ module Redis::KeyHash
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- # TODO: rubocop
12
11
 
13
12
  # TODO: rdoc
14
13
 
14
+ # KNOWN_STYLES are the known reference styles.
15
15
  #
16
- # TODO: KNOWN_STYLES hash, etc, move comments around
17
- #
16
+ KNOWN_STYLES ||= {
17
+
18
+ # The :style => :rc implementation matches Redis Cluster exactly
19
+ # and is taken largely from the reference example provided in
20
+ # http://redis.io/topics/cluster-spec.
21
+ #
22
+ :rc => /^[^{]*{([^}]+)}/, # RC uses first {}-expr, but only if nonempty
23
+
24
+ # The :style => :rlec implementation is partly speculative. It
25
+ # is mostly interpreted from the default RedisLabs Enterprise
26
+ # Cluster documentation at
27
+ # https://redislabs.com/redis-enterprise-documentation/concepts-architecture/architecture/database-clustering/,
28
+ # plus our experience at ProsperWorks that, out of the box, RLEC
29
+ # uses the *last* {}-expr, not the first as in RC, from :rc
30
+ # (which we would not care about), they are also structually
31
+ # different (which can cause bugs unless we take special care).
32
+ # :rc uses the first {}-expr in the, :rlec uses the last
33
+ # {}-expr.
34
+ #
35
+ :rlec => /.*\{(.*)\}.*/, # RLEC default per docs, uses last {}-expr
36
+
37
+ }.freeze
18
38
 
19
39
  # The default for all_in_one_slot? and all_in_one_slot! is
20
40
  # [:rc,:rlec] to encourage the of portable persistent hashing
@@ -97,20 +117,6 @@ module Redis::KeyHash
97
117
  # Computes the hash tag for a given key under a given Redis
98
118
  # clustering algorithm.
99
119
  #
100
- # The :style => :rc implementation matches Redis Cluster exactly
101
- # and is taken largely from the reference example provided in
102
- # http://redis.io/topics/cluster-spec.
103
- #
104
- # The :style => :rlec implementation is partly speculative. It is
105
- # mostly interpreted from the default RedisLabs Enterprise Cluster
106
- # document
107
- # https://redislabs.com/redis-enterprise-documentation/concepts-architecture/architecture/database-clustering/
108
- # plus our experience at ProsperWorks that, out of the box, RLEC
109
- # uses the *last* {}-expr, not the first as in RC, from :rc (which
110
- # we would not care about), they are also structually different
111
- # (which can cause bugs unless we take special care). :rc uses
112
- # the first {}-expr in the, :rlec uses the last {}-expr.
113
- #
114
120
  # @param String key to be hashed
115
121
  #
116
122
  # @param Symbol :rc or rlec or Regexp which defines one capture group
@@ -119,13 +125,10 @@ module Redis::KeyHash
119
125
  #
120
126
  def hash_tag(key, style: DEFAULT_STYLE)
121
127
  regexp = nil
122
- case style
123
- when :rc
124
- regexp = /{([^}]*)}/ # RC uses the first {}-expr
125
- when :rlec
126
- regexp = /.*\{(.*)\}.*/ # RLEC default per docs, uses last {}-expr
127
- when Regexp
128
- regexp = style # you can define your own
128
+ if KNOWN_STYLES.has_key?(style)
129
+ regexp = KNOWN_STYLES[style] # some are predefined
130
+ elsif style.is_a?(Regexp)
131
+ regexp = style # you can define your own
129
132
  end
130
133
  if !regexp
131
134
  raise ArgumentError, "bogus style #{style}"
@@ -1,17 +1,20 @@
1
1
  class Redis
2
2
  module KeyHash
3
3
  #
4
- # Version plan:
4
+ # Version plan/history:
5
5
  #
6
- # 0.0.1 - still in Prosperworks/ALI/vendor/gems/redis-key_hash
6
+ # 0.0.1 - Still in Prosperworks/ALI/vendor/gems/redis-key_hash.
7
7
  #
8
- # 0.0.2 - broke out into Prosperworks/redis-key_hash
8
+ # 0.0.2 - Broke out into Prosperworks/redis-key_hash, make public.
9
9
  #
10
- # 0.1.0 - big README.md and Rdoc update, open repo
10
+ # 0.0.3 - Fix :rc to match https://redis.io/topics/cluster-spec,
11
+ # added Rubocop checks.
11
12
  #
12
- # 0.2.0 - solicit and incorporate initial feedback from select
13
- # beta external users
13
+ # 0.1.0 - (future) Big README.md and Rdoc update, solicit feedback
14
+ # from select external beta users.
14
15
  #
15
- VERSION = "0.0.2" # broken into standalone repo, not polished
16
+ # 0.2.0 - (future) Incorporate feedback, announce.
17
+ #
18
+ VERSION = '0.0.3'
16
19
  end
17
20
  end
@@ -5,12 +5,8 @@ require 'redis/key_hash/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "redis-key_hash"
7
7
  spec.version = Redis::KeyHash::VERSION
8
- spec.authors = [
9
- "jhwillett"
10
- ]
11
- spec.email = [
12
- "jhw@prosperworks.com"
13
- ]
8
+ spec.authors = ["jhwillett"]
9
+ spec.email = ["jhw@prosperworks.com"]
14
10
  spec.license = 'MIT'
15
11
 
16
12
  spec.summary = 'Tests Redis Cluster key hash slot agreement'
@@ -18,23 +14,6 @@ Gem::Specification.new do |spec|
18
14
  spec.description = %{
19
15
  redis-key_hash provides tests of key hash slot agreement for use with
20
16
  Redis Cluster and RedisLabs Enterprise Cluster.
21
-
22
- Redis Cluster (RC) and RedisLabs Enterprise Cluster (RLEC) both
23
- require that all keys in multi-key operations hash to the same node.
24
- They use slightly different default hashing algorithms and RLEC offers
25
- customizable hash pattersn.
26
-
27
- It is impossible to predict which nodes will host each shard, and
28
- difficult to predict which slot will host each key. But it is easy to
29
- identify the key hash tag which RC or RLEC will use to select a shard.
30
- Where key hash tags agree, we can be certain that slots and nodes will
31
- also agree - even if hash tag disagreement does not always imply slot
32
- or node disagreement.
33
-
34
- By pulling this check into Ruby we can arrange to fail fast, before
35
- sending a command to Redis which is at risk of CROSSLOT failure. We
36
- can also validate key management schemes in unit tests which run
37
- without support services or with a non-sharded Redis.
38
17
  }
39
18
 
40
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-key_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jhwillett
@@ -56,23 +56,6 @@ description: |2
56
56
 
57
57
  redis-key_hash provides tests of key hash slot agreement for use with
58
58
  Redis Cluster and RedisLabs Enterprise Cluster.
59
-
60
- Redis Cluster (RC) and RedisLabs Enterprise Cluster (RLEC) both
61
- require that all keys in multi-key operations hash to the same node.
62
- They use slightly different default hashing algorithms and RLEC offers
63
- customizable hash pattersn.
64
-
65
- It is impossible to predict which nodes will host each shard, and
66
- difficult to predict which slot will host each key. But it is easy to
67
- identify the key hash tag which RC or RLEC will use to select a shard.
68
- Where key hash tags agree, we can be certain that slots and nodes will
69
- also agree - even if hash tag disagreement does not always imply slot
70
- or node disagreement.
71
-
72
- By pulling this check into Ruby we can arrange to fail fast, before
73
- sending a command to Redis which is at risk of CROSSLOT failure. We
74
- can also validate key management schemes in unit tests which run
75
- without support services or with a non-sharded Redis.
76
59
  email:
77
60
  - jhw@prosperworks.com
78
61
  executables: []
@@ -80,6 +63,8 @@ extensions: []
80
63
  extra_rdoc_files: []
81
64
  files:
82
65
  - ".gitignore"
66
+ - ".rubocop.yml"
67
+ - ".rubocop_todo.yml"
83
68
  - ".travis.yml"
84
69
  - Gemfile
85
70
  - LICENSE