redis-script_manager 0.0.3 → 0.0.4

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: b3bf62263d3927088efc2136df3cb22f5a29ce54
4
- data.tar.gz: 4c0ee1b2b1d56ae9afe620cf9397cf159bd37120
3
+ metadata.gz: 971772a9f0906a9df2c012d8ad100a71941ad577
4
+ data.tar.gz: 3a3c6fddacff400288171761caf7a8ee6361edf4
5
5
  SHA512:
6
- metadata.gz: 9a1ff6adf5859dfabe42b8e93a87f1b74ceb7e571f5f7265b72fc4ca5787aa1e002ebe905dbf81273f3216ee7113372f8e7f9c5d2bbcb8e42c70ee9cce54bf38
7
- data.tar.gz: be3ca085567587e9507b45917bea13d068a1616f7a18198d1d0856a197d3f72a8ddd8f1c5d5417e31a93bda31bf5c61d2f393cfeb696844189ca608c0816c81c
6
+ metadata.gz: a54825b7aeb87346e64ff33124164ce193f389ae95418d714a3ae8d0f27b8e17cd14a3f45d17a38bb567ede84b5a9af43fa19fe45f3e9bd086f13604340eac40
7
+ data.tar.gz: 9de8a278b7842a879cfdf58614f174eda0e4c816b6b160187d5cc06e17281392005b2c65ce034a859c938f9030bfb6e4d7d3e4252fcdbd6dac4c54d94f504f7f
@@ -1,6 +1,199 @@
1
- inherit_from: .rubocop_todo.yml
1
+
2
2
  AllCops:
3
3
  Include:
4
4
  - Rakefile
5
5
  - Gemfile
6
6
  - '*.gemspec'
7
+
8
+ # I like this Metric in principle, but I don't like the default max of
9
+ # 15.
10
+ #
11
+ # Also, as per Metrics/ClassLength IMO this kind of limit should not
12
+ # apply to test code (I get up to 318 over there).
13
+ #
14
+ Metrics/AbcSize:
15
+ Max: 100
16
+ Exclude:
17
+ - 'test/**/*.rb'
18
+
19
+ # Broadly speaking, test code gets a pass for most of the Metrics family.
20
+ #
21
+ # IMO test code is not the place get pedantic about class length,
22
+ # method complexity, etc. One should be encouraged to add more tests
23
+ # with minimal friction, not forced to make a hard choice between
24
+ # cutting tests or splitting up my test suites.
25
+ #
26
+ Metrics/BlockLength:
27
+ Exclude:
28
+ - 'test/**/*.rb'
29
+
30
+ # Ditto I believe in more permissive rules in test code.
31
+ #
32
+ Metrics/ClassLength:
33
+ Max: 400
34
+ Exclude:
35
+ - 'test/**/*.rb'
36
+
37
+ # Redis::ScriptManager#eval_gently is indeed overly complex but I am
38
+ # happy with it until the next time something goes wrong.
39
+ #
40
+ # Also ditto I believe in more permissive rules in test code.
41
+ #
42
+ Metrics/CyclomaticComplexity:
43
+ Max: 30
44
+ Exclude:
45
+ - 'test/**/*.rb'
46
+ Metrics/MethodLength:
47
+ Max: 100
48
+ Exclude:
49
+ - 'test/**/*.rb'
50
+ Metrics/PerceivedComplexity:
51
+ Max: 21
52
+ Exclude:
53
+ - 'test/**/*.rb'
54
+
55
+ # I put extra spaces in a lot of expressions for a lot of different
56
+ # reasons, including especially readability.
57
+ #
58
+ # I reject these cops.
59
+ #
60
+ Layout:
61
+ Enabled: false
62
+
63
+ # I like a lot of the Lint tests, but not these.
64
+ #
65
+ Lint/AmbiguousBlockAssociation: # obnoxiously rejects idiomatic Ruby
66
+ Enabled: false
67
+
68
+ # This does no more than insist I type "format" instead of "sprintf",
69
+ # where the two are aliases.
70
+ #
71
+ Style/FormatString:
72
+ Enabled: false
73
+
74
+ # This complains that:
75
+ #
76
+ # if foo
77
+ # foo.bar
78
+ # end
79
+ #
80
+ # could instead be:
81
+ #
82
+ # foo.bar if foo
83
+ #
84
+ # ...which I reject, not least because the former is a lot easier to
85
+ # fit into an 80 character line.
86
+ #
87
+ Style/GuardClause:
88
+ Enabled: false
89
+
90
+ # There is nothing wrong with Ruby 1.9 Hash syntax.
91
+ #
92
+ Style/HashSyntax:
93
+ Enabled: false
94
+
95
+ # No. Indeed, postfix if can often drive a line over 80 columns wide.
96
+ #
97
+ Style/IfUnlessModifier:
98
+ Enabled: false
99
+
100
+ # No. There is nothing wrong with "if !foo".
101
+ #
102
+ # As far as I'm concerned, "unless" is in poor taste because it means
103
+ # I have to think in English in two different logical senses - and
104
+ # English is a poor language for logical senses.
105
+ #
106
+ Style/NegatedIf:
107
+ Enabled: false
108
+
109
+ # No.
110
+ #
111
+ # I can catenate strings with + if I want to. Indeed, it looks better
112
+ # in my editor.
113
+ #
114
+ Style/LineEndConcatenation:
115
+ Enabled: false
116
+
117
+ # Too pedantic.
118
+ #
119
+ Style/NumericLiterals:
120
+ Enabled: false
121
+
122
+ # This complains that:
123
+ #
124
+ # raise RuntimeError, "foo"
125
+ #
126
+ # Does not need the RuntimeError because it is redundant.
127
+ #
128
+ # I do not accept a requirement not to be explicit.
129
+ #
130
+ Style/RedundantException:
131
+ Enabled: false
132
+
133
+ # "Do not use semicolons to terminate expressions."
134
+ #
135
+ # That's great when I terminate a single-line expression with a
136
+ # redundant semicolo because I forget I'm not using C.
137
+ #
138
+ # But when I'm using a semicolon to separate two expressions there is
139
+ # no other choice. So this really ought to be Style/OneExprPerLine,
140
+ # which I reject.
141
+ #
142
+ Style/Semicolon:
143
+ Enabled: false
144
+
145
+ # No.
146
+ #
147
+ # Some lines must have '\"'. It is ugly to use a mix of '"' and '\''
148
+ # in LoCs which are close to one another. Therefore, banning '"' if
149
+ # '"' is not strictly necessary drives visual inconsistency.
150
+ #
151
+ Style/StringLiterals:
152
+ Enabled: false
153
+
154
+ # This is the same kind of obnoxious pedantry which drove Hungarian
155
+ # Notation.
156
+ #
157
+ # The [] literal syntax is perfectly servicable and there is no point
158
+ # _tightly_ coupling it to the content of the array. That's why we
159
+ # have context-free grammers!
160
+ #
161
+ Style/SymbolArray:
162
+ Enabled: false
163
+
164
+ # Shockingly, this cop requires us to *OMIT*, not *INCLUDE* parens in
165
+ # ternery conditons.
166
+ #
167
+ # IMO this one is actively harmful in that it discourages attention to
168
+ # clarity and avoiding some nasty precedence surprises.
169
+ #
170
+ Style/TernaryParentheses:
171
+ Enabled: false
172
+
173
+ # I am a huge fan of using trailing commas when I break an argument
174
+ # list down one-per line.
175
+ #
176
+ # As such, I reject this test.
177
+ #
178
+ Style/TrailingCommaInLiteral:
179
+ Enabled: false
180
+
181
+ # No. attr_writer, attr_reader, etc. are strictly optional.
182
+ #
183
+ # If I want to use the longer, less sugary form that is my business.
184
+ #
185
+ # I especially believe this where, for instance, I have a trivial
186
+ # reader but a non-trivial writer. I want consistency between them -
187
+ # which would be prohibited by this requirement.
188
+ Style/TrivialAccessors:
189
+ Enabled: false
190
+
191
+ # Too pedantic. I am starting to think I should switch from "opt out"
192
+ # to "opt in" on the Style family.
193
+ #
194
+ Style/WordArray:
195
+ Enabled: false
196
+ Style/YodaCondition:
197
+ Enabled: false
198
+ Style/ZeroLengthPredicate:
199
+ Enabled: false
@@ -1,6 +1,10 @@
1
1
  require "redis/script_manager/version"
2
2
 
3
3
  class Redis
4
+
5
+ # Utility to efficiently manage SCRIPT LOAD, EVAL, and EVALSHA over
6
+ # all Redis/Lua scripts.
7
+ #
4
8
  class ScriptManager
5
9
 
6
10
  # TODO: rdoc
@@ -74,7 +78,7 @@ class Redis
74
78
  # within a pipeline.
75
79
  #
76
80
  if configuration.do_minify_lua
77
- lua = self.minify_lua(lua)
81
+ lua = minify_lua(lua)
78
82
  end
79
83
  if lua.size < configuration.max_tiny_lua
80
84
  _statsd_increment("eval")
@@ -113,20 +117,18 @@ class Redis
113
117
  #
114
118
  sha = Digest::SHA1.hexdigest(lua)
115
119
  sha_connection_key = [redis.object_id,sha]
116
- if !@@preloaded_shas.include?(sha_connection_key)
120
+ if !@preloaded_shas.include?(sha_connection_key)
117
121
  _statsd_increment("preloaded_shas.cache_miss")
118
122
  new_sha = redis.script(:load,lua)
119
- if !new_sha.is_a?(Redis::Future)
120
- if sha != new_sha
121
- raise RuntimeError, "mismatch #{sha} vs #{new_sha} for lua #{lua}"
122
- end
123
+ if !new_sha.is_a?(Redis::Future) && sha != new_sha
124
+ raise RuntimeError, "mismatch #{sha} vs #{new_sha} for lua #{lua}"
123
125
  end
124
- @@preloaded_shas << sha_connection_key
126
+ @preloaded_shas << sha_connection_key
125
127
  else
126
128
  _statsd_increment("preloaded_shas.cache_hit")
127
129
  end
128
130
  result = redis.evalsha(sha,keys,args)
129
- if configuration.preload_cache_size < @@preloaded_shas.size
131
+ if configuration.preload_cache_size < @preloaded_shas.size
130
132
  #
131
133
  # To defend against unbound cache size, at a predetermined
132
134
  # limit throw away half of them.
@@ -138,10 +140,10 @@ class Redis
138
140
  # bound.
139
141
  #
140
142
  _statsd_increment("preloaded_shas.cache_purge")
141
- num_to_keep = @@preloaded_shas.size / 2
142
- @@preloaded_shas = @@preloaded_shas.to_a.sample(num_to_keep)
143
+ num_to_keep = @preloaded_shas.size / 2
144
+ @preloaded_shas = @preloaded_shas.to_a.sample(num_to_keep)
143
145
  end
144
- cache_size = @@preloaded_shas.size
146
+ cache_size = @preloaded_shas.size
145
147
  _statsd_timing("preloaded_shas.cache_size",cache_size)
146
148
  return result
147
149
  end
@@ -176,10 +178,10 @@ class Redis
176
178
  end
177
179
  end
178
180
 
179
- @@preloaded_shas = Set[] # [redis.object_id,sha(lua)] which have been loaded
181
+ @preloaded_shas = Set[] # [redis.object_id,sha(lua)] which have been loaded
180
182
 
181
183
  def self.purge_preloaded_shas # for test, clean state
182
- @@preloaded_shas = Set[]
184
+ @preloaded_shas = Set[]
183
185
  end
184
186
 
185
187
  # To save bandwidth, minify the Lua code.
@@ -241,6 +243,8 @@ class Redis
241
243
  yield configuration
242
244
  end
243
245
 
246
+ # Configuration interface for Redis::ScriptManager.
247
+ #
244
248
  class Configuration
245
249
 
246
250
  # Defaults to nil. If non-nil, lots of stats will be tracked via
@@ -7,14 +7,19 @@ class Redis
7
7
  #
8
8
  # 0.0.2 - Broke out into Prosperworks/redis-script_manager, make public.
9
9
  #
10
- # 0.0.3 - Got .travis.yml working with a live redis-server, some
11
- # cleanup, added Rubocop.
10
+ # 0.0.3 - Got .travis.yml working with a live redis-server.
11
+ #
12
+ # Initial Rubocop integration.
13
+ #
14
+ # Misc cleanup.
15
+ #
16
+ # 0.0.4 - Rubocop polish and defiance.
12
17
  #
13
18
  # 0.1.0 - (future) Big README.md and Rdoc update, solicit feedback
14
19
  # from select external beta users.
15
20
  #
16
21
  # 0.2.0 - (future) Incorporate feedback, announce.
17
22
  #
18
- VERSION = '0.0.3'
23
+ VERSION = '0.0.4'.freeze
19
24
  end
20
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-script_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jhwillett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,6 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rubocop.yml"
92
- - ".rubocop_todo.yml"
93
92
  - ".travis.yml"
94
93
  - Gemfile
95
94
  - LICENSE
@@ -1,266 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2017-08-29 15:12:56 -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: 10
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
12
- Layout/EmptyLineBetweenDefs:
13
- Exclude:
14
- - 'lib/redis/script_manager.rb'
15
- - 'test/redis/script_manager_test.rb'
16
-
17
- # Offense count: 2
18
- # Cop supports --auto-correct.
19
- # Configuration parameters: EnforcedStyle, SupportedStyles.
20
- # SupportedStyles: empty_lines, no_empty_lines
21
- Layout/EmptyLinesAroundBlockBody:
22
- Exclude:
23
- - 'redis-script_manager.gemspec'
24
-
25
- # Offense count: 7
26
- # Cop supports --auto-correct.
27
- # Configuration parameters: EnforcedStyle, SupportedStyles.
28
- # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
29
- Layout/EmptyLinesAroundClassBody:
30
- Exclude:
31
- - 'lib/redis/script_manager.rb'
32
- - 'test/redis/script_manager_test.rb'
33
-
34
- # Offense count: 19
35
- # Cop supports --auto-correct.
36
- # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
37
- Layout/ExtraSpacing:
38
- Exclude:
39
- - 'lib/redis/script_manager.rb'
40
- - 'test/redis/script_manager_test.rb'
41
-
42
- # Offense count: 161
43
- # Cop supports --auto-correct.
44
- Layout/SpaceAfterComma:
45
- Exclude:
46
- - 'lib/redis/script_manager.rb'
47
- - 'test/redis/script_manager_test.rb'
48
-
49
- # Offense count: 2
50
- # Cop supports --auto-correct.
51
- # Configuration parameters: SupportedStyles.
52
- # SupportedStyles: space, no_space
53
- Layout/SpaceAroundEqualsInParameterDefault:
54
- EnforcedStyle: no_space
55
-
56
- # Offense count: 9
57
- # Cop supports --auto-correct.
58
- # Configuration parameters: AllowForAlignment.
59
- Layout/SpaceAroundOperators:
60
- Exclude:
61
- - 'lib/redis/script_manager.rb'
62
- - 'test/redis/script_manager_test.rb'
63
-
64
- # Offense count: 3
65
- # Cop supports --auto-correct.
66
- # Configuration parameters: AllowForAlignment.
67
- Layout/SpaceBeforeFirstArg:
68
- Exclude:
69
- - 'test/redis/script_manager_test.rb'
70
-
71
- # Offense count: 15
72
- # Cop supports --auto-correct.
73
- Layout/SpaceBeforeSemicolon:
74
- Exclude:
75
- - 'test/redis/script_manager_test.rb'
76
-
77
- # Offense count: 13
78
- # Cop supports --auto-correct.
79
- Layout/SpaceInsideBrackets:
80
- Exclude:
81
- - 'test/redis/script_manager_test.rb'
82
-
83
- # Offense count: 2
84
- # Cop supports --auto-correct.
85
- Layout/SpaceInsideParens:
86
- Exclude:
87
- - 'test/redis/script_manager_test.rb'
88
-
89
- # Offense count: 7
90
- Metrics/AbcSize:
91
- Max: 81
92
-
93
- # Offense count: 4
94
- # Configuration parameters: CountComments, ExcludedMethods.
95
- Metrics/BlockLength:
96
- Max: 99
97
-
98
- # Offense count: 1
99
- # Configuration parameters: CountBlocks.
100
- Metrics/BlockNesting:
101
- Max: 4
102
-
103
- # Offense count: 2
104
- # Configuration parameters: CountComments.
105
- Metrics/ClassLength:
106
- Max: 425
107
-
108
- # Offense count: 1
109
- Metrics/CyclomaticComplexity:
110
- Max: 20
111
-
112
- # Offense count: 7
113
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
114
- # URISchemes: http, https
115
- Metrics/LineLength:
116
- Max: 81
117
-
118
- # Offense count: 7
119
- # Configuration parameters: CountComments.
120
- Metrics/MethodLength:
121
- Max: 78
122
-
123
- # Offense count: 1
124
- Metrics/PerceivedComplexity:
125
- Max: 21
126
-
127
- # Offense count: 1
128
- # Configuration parameters: EnforcedStyle, SupportedStyles.
129
- # SupportedStyles: nested, compact
130
- Style/ClassAndModuleChildren:
131
- Exclude:
132
- - 'test/redis/script_manager_test.rb'
133
-
134
- # Offense count: 4
135
- Style/ClassVars:
136
- Exclude:
137
- - 'lib/redis/script_manager.rb'
138
- - 'test/redis/script_manager_test.rb'
139
-
140
- # Offense count: 2
141
- Style/Documentation:
142
- Exclude:
143
- - 'spec/**/*'
144
- - 'test/**/*'
145
- - 'lib/redis/script_manager.rb'
146
-
147
- # Offense count: 2
148
- # Configuration parameters: MinBodyLength.
149
- Style/GuardClause:
150
- Exclude:
151
- - 'lib/redis/script_manager.rb'
152
-
153
- # Offense count: 2
154
- # Cop supports --auto-correct.
155
- # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
156
- # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
157
- Style/HashSyntax:
158
- Exclude:
159
- - 'Rakefile'
160
- - 'test/redis/script_manager_test.rb'
161
-
162
- # Offense count: 4
163
- # Cop supports --auto-correct.
164
- # Configuration parameters: MaxLineLength.
165
- Style/IfUnlessModifier:
166
- Exclude:
167
- - 'lib/redis/script_manager.rb'
168
-
169
- # Offense count: 43
170
- # Cop supports --auto-correct.
171
- Style/LineEndConcatenation:
172
- Exclude:
173
- - 'test/redis/script_manager_test.rb'
174
-
175
- # Offense count: 3
176
- Style/MultilineTernaryOperator:
177
- Exclude:
178
- - 'test/redis/script_manager_test.rb'
179
-
180
- # Offense count: 1
181
- # Cop supports --auto-correct.
182
- Style/MutableConstant:
183
- Exclude:
184
- - 'lib/redis/script_manager/version.rb'
185
-
186
- # Offense count: 9
187
- # Cop supports --auto-correct.
188
- # Configuration parameters: EnforcedStyle, SupportedStyles.
189
- # SupportedStyles: both, prefix, postfix
190
- Style/NegatedIf:
191
- Exclude:
192
- - 'lib/redis/script_manager.rb'
193
- - 'test/redis/script_manager_test.rb'
194
-
195
- # Offense count: 2
196
- # Cop supports --auto-correct.
197
- Style/RedundantException:
198
- Exclude:
199
- - 'lib/redis/script_manager.rb'
200
-
201
- # Offense count: 1
202
- # Cop supports --auto-correct.
203
- Style/RedundantSelf:
204
- Exclude:
205
- - 'lib/redis/script_manager.rb'
206
-
207
- # Offense count: 15
208
- # Cop supports --auto-correct.
209
- # Configuration parameters: AllowAsExpressionSeparator.
210
- Style/Semicolon:
211
- Exclude:
212
- - 'test/redis/script_manager_test.rb'
213
-
214
- # Offense count: 84
215
- # Cop supports --auto-correct.
216
- # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
217
- # SupportedStyles: single_quotes, double_quotes
218
- Style/StringLiterals:
219
- Exclude:
220
- - 'Rakefile'
221
- - 'bin/console'
222
- - 'lib/redis/script_manager.rb'
223
- - 'redis-script_manager.gemspec'
224
- - 'test/redis/script_manager_test.rb'
225
-
226
- # Offense count: 1
227
- # Cop supports --auto-correct.
228
- # Configuration parameters: MinSize, SupportedStyles.
229
- # SupportedStyles: percent, brackets
230
- Style/SymbolArray:
231
- EnforcedStyle: brackets
232
-
233
- # Offense count: 13
234
- # Cop supports --auto-correct.
235
- # Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
236
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
237
- Style/TrailingCommaInLiteral:
238
- Exclude:
239
- - 'test/redis/script_manager_test.rb'
240
-
241
- # Offense count: 1
242
- # Cop supports --auto-correct.
243
- # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
244
- # Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
245
- Style/TrivialAccessors:
246
- Exclude:
247
- - 'lib/redis/script_manager.rb'
248
-
249
- # Offense count: 9
250
- # Cop supports --auto-correct.
251
- # Configuration parameters: SupportedStyles, MinSize, WordRegex.
252
- # SupportedStyles: percent, brackets
253
- Style/WordArray:
254
- EnforcedStyle: brackets
255
-
256
- # Offense count: 2
257
- # Cop supports --auto-correct.
258
- Style/YodaCondition:
259
- Exclude:
260
- - 'lib/redis/script_manager.rb'
261
-
262
- # Offense count: 1
263
- # Cop supports --auto-correct.
264
- Style/ZeroLengthPredicate:
265
- Exclude:
266
- - 'lib/redis/script_manager.rb'