redis-json 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0c4992d626b03ba86229fb96d18713a5ae0154e566c60a4740444c9dfa42a8e7
4
+ data.tar.gz: 005bbd5b6e66ddf75e83a585251099d07ad8a3cb9b00b15b0f6ba12973c6e475
5
+ SHA512:
6
+ metadata.gz: 54a918c7cf3a6e85025f1f2fa168c17dcfac7b0e2bc931c08f4288614b7836773eb6c02f14493333fd757f3c2910029889cdc063a6629b6404c0e245f6ca18da
7
+ data.tar.gz: 71deaea8c939d271c9d30453886af0fe314ae3c91dd1068a0f60f898a463877a6398eba38d1bff1b128d05f3245d1967e22d40e3e8d710c6e27f293a40e63aef
data/.rubocop.yml ADDED
@@ -0,0 +1,451 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**'
4
+
5
+ Gemspec/DeprecatedAttributeAssignment:
6
+ Enabled: true
7
+
8
+ Gemspec/DevelopmentDependencies:
9
+ Enabled: true
10
+
11
+ Gemspec/RequireMFA:
12
+ Enabled: false
13
+
14
+ Layout/AccessModifierIndentation:
15
+ EnforcedStyle: outdent
16
+
17
+ Layout/BeginEndAlignment:
18
+ EnforcedStyleAlignWith: begin
19
+
20
+ Layout/BlockAlignment:
21
+ EnforcedStyleAlignWith: start_of_block
22
+
23
+ Layout/CommentIndentation:
24
+ AllowForAlignment: true
25
+
26
+ Layout/EmptyLineAfterMultilineCondition:
27
+ Enabled: true
28
+
29
+ Layout/EndOfLine:
30
+ EnforcedStyle: lf
31
+
32
+ Layout/ExtraSpacing:
33
+ AllowForAlignment: true
34
+ AllowBeforeTrailingComments: true
35
+
36
+ Layout/HashAlignment:
37
+ EnforcedHashRocketStyle: table
38
+ EnforcedColonStyle: table
39
+ EnforcedLastArgumentHashStyle: ignore_implicit
40
+
41
+ Layout/LineContinuationLeadingSpace:
42
+ Enabled: true
43
+
44
+ Layout/LineContinuationSpacing:
45
+ Enabled: true
46
+
47
+ Layout/LineEndStringConcatenationIndentation:
48
+ Enabled: true
49
+
50
+ Layout/MultilineArrayLineBreaks:
51
+ Enabled: true
52
+
53
+ Layout/MultilineAssignmentLayout:
54
+ Enabled: true
55
+ EnforcedStyle: same_line
56
+
57
+ Layout/MultilineHashKeyLineBreaks:
58
+ Enabled: true
59
+
60
+ Layout/MultilineMethodArgumentLineBreaks:
61
+ Enabled: true
62
+
63
+ Layout/MultilineMethodCallIndentation:
64
+ EnforcedStyle: indented_relative_to_receiver
65
+
66
+ Layout/SingleLineBlockChain:
67
+ Enabled: true
68
+
69
+ Layout/SpaceAroundEqualsInParameterDefault:
70
+ EnforcedStyle: no_space
71
+
72
+ Layout/SpaceAroundOperators:
73
+ EnforcedStyleForExponentOperator: space
74
+
75
+ Layout/SpaceBeforeBrackets:
76
+ Enabled: true
77
+
78
+ Layout/SpaceInsideHashLiteralBraces:
79
+ EnforcedStyle: no_space
80
+
81
+ Layout/TrailingWhitespace:
82
+ AllowInHeredoc: true
83
+
84
+ Lint/AmbiguousAssignment:
85
+ Enabled: true
86
+
87
+ Lint/AmbiguousOperatorPrecedence:
88
+ Enabled: true
89
+
90
+ Lint/AmbiguousRange:
91
+ Enabled: true
92
+ RequireParenthesesForMethodChains: true
93
+
94
+ Lint/AssignmentInCondition:
95
+ AllowSafeAssignment: false
96
+
97
+ Lint/ConstantOverwrittenInRescue:
98
+ Enabled: true
99
+
100
+ Lint/DeprecatedConstants:
101
+ Enabled: true
102
+
103
+ Lint/DuplicateBranch:
104
+ Enabled: true
105
+ IgnoreLiteralBranches: true
106
+ IgnoreConstantBranches: true
107
+
108
+ Lint/DuplicateMagicComment:
109
+ Enabled: true
110
+
111
+ Lint/DuplicateRegexpCharacterClassElement:
112
+ Enabled: true
113
+
114
+ Lint/EmptyBlock:
115
+ Enabled: true
116
+
117
+ Lint/EmptyClass:
118
+ Enabled: true
119
+ AllowComments: true
120
+
121
+ Lint/EmptyInPattern:
122
+ Enabled: true
123
+
124
+ Lint/HeredocMethodCallPosition:
125
+ Enabled: true
126
+
127
+ Lint/IncompatibleIoSelectWithFiberScheduler:
128
+ Enabled: false
129
+
130
+ Lint/LambdaWithoutLiteralBlock:
131
+ Enabled: true
132
+
133
+ Lint/NoReturnInBeginEndBlocks:
134
+ Enabled: true
135
+
136
+ Lint/NonAtomicFileOperation:
137
+ Enabled: true
138
+
139
+ Lint/NumberedParameterAssignment:
140
+ Enabled: true
141
+
142
+ Lint/OrAssignmentToConstant:
143
+ Enabled: true
144
+
145
+ Lint/RedundantDirGlobSort:
146
+ Enabled: true
147
+
148
+ Lint/RedundantSplatExpansion:
149
+ AllowPercentLiteralArrayArgument: false
150
+
151
+ Lint/RefinementImportMethods:
152
+ Enabled: true
153
+
154
+ Lint/RequireRangeParentheses:
155
+ Enabled: true
156
+
157
+ Lint/RequireRelativeSelfPath:
158
+ Enabled: true
159
+
160
+ Lint/SymbolConversion:
161
+ Enabled: true
162
+
163
+ Lint/ToEnumArguments:
164
+ Enabled: true
165
+
166
+ Lint/TripleQuotes:
167
+ Enabled: true
168
+
169
+ Lint/UnexpectedBlockArity:
170
+ Enabled: true
171
+
172
+ Lint/UnmodifiedReduceAccumulator:
173
+ Enabled: true
174
+
175
+ Lint/UnusedBlockArgument:
176
+ AutoCorrect: false
177
+
178
+ Lint/UnusedMethodArgument:
179
+ AutoCorrect: false
180
+
181
+ Lint/UselessRescue:
182
+ Enabled: true
183
+
184
+ Lint/UselessRuby2Keywords:
185
+ Enabled: true
186
+
187
+ Metrics:
188
+ Enabled: false
189
+
190
+ Naming/BlockForwarding:
191
+ Enabled: true
192
+
193
+ Naming/InclusiveLanguage:
194
+ Enabled: false
195
+
196
+ Security/CompoundHash:
197
+ Enabled: true
198
+
199
+ Security/Eval:
200
+ Enabled: false
201
+
202
+ Security/IoMethods:
203
+ Enabled: true
204
+
205
+ Style/AccessorGrouping:
206
+ EnforcedStyle: separated
207
+
208
+ Style/ArgumentsForwarding:
209
+ Enabled: false
210
+
211
+ Style/ArrayIntersect:
212
+ Enabled: true
213
+
214
+ Style/AutoResourceCleanup:
215
+ Enabled: true
216
+
217
+ Style/CollectionCompact:
218
+ Enabled: true
219
+
220
+ Style/CollectionMethods:
221
+ Enabled: true
222
+
223
+ Style/ComparableClamp:
224
+ Enabled: true
225
+
226
+ Style/ConcatArrayLiterals:
227
+ Enabled: true
228
+
229
+ Style/DirEmpty:
230
+ Enabled: true
231
+
232
+ Style/DocumentDynamicEvalDefinition:
233
+ Enabled: false
234
+
235
+ Style/Documentation:
236
+ Enabled: false
237
+
238
+ Style/DocumentationMethod:
239
+ Enabled: false
240
+
241
+ Style/DoubleNegation:
242
+ EnforcedStyle: forbidden
243
+
244
+ Style/EmptyHeredoc:
245
+ Enabled: true
246
+
247
+ Style/EmptyMethod:
248
+ EnforcedStyle: expanded
249
+
250
+ Style/EndlessMethod:
251
+ Enabled: true
252
+ EnforcedStyle: disallow
253
+
254
+ Style/EnvHome:
255
+ Enabled: true
256
+
257
+ Style/FetchEnvVar:
258
+ Enabled: false
259
+
260
+ Style/FileEmpty:
261
+ Enabled: true
262
+
263
+ Style/FileRead:
264
+ Enabled: true
265
+
266
+ Style/FileWrite:
267
+ Enabled: true
268
+
269
+ Style/FormatString:
270
+ EnforcedStyle: percent
271
+
272
+ Style/FrozenStringLiteralComment:
273
+ Enabled: false
274
+
275
+ Style/HashConversion:
276
+ Enabled: true
277
+
278
+ Style/HashExcept:
279
+ Enabled: true
280
+
281
+ Style/HashSyntax:
282
+ EnforcedShorthandSyntax: never
283
+
284
+ Style/IfWithBooleanLiteralBranches:
285
+ Enabled: true
286
+
287
+ Style/ImplicitRuntimeError:
288
+ Enabled: true
289
+
290
+ Style/InPatternThen:
291
+ Enabled: true
292
+
293
+ Style/IpAddresses:
294
+ Enabled: true
295
+
296
+ Style/MagicCommentFormat:
297
+ Enabled: true
298
+
299
+ Style/MapCompactWithConditionalBlock:
300
+ Enabled: true
301
+
302
+ Style/MapToHash:
303
+ Enabled: true
304
+
305
+ Style/MapToSet:
306
+ Enabled: true
307
+
308
+ Style/MethodCallWithArgsParentheses:
309
+ Enabled: true
310
+ EnforcedStyle: omit_parentheses
311
+ AllowParenthesesInMultilineCall: true
312
+ AllowParenthesesInChaining: true
313
+ AllowParenthesesInCamelCaseMethod: true
314
+
315
+ Style/MethodDefParentheses:
316
+ EnforcedStyle: require_no_parentheses_except_multiline
317
+
318
+ Style/MinMaxComparison:
319
+ Enabled: true
320
+
321
+ Style/MultilineBlockChain:
322
+ Enabled: false
323
+
324
+ Style/MultilineInPatternThen:
325
+ Enabled: true
326
+
327
+ Style/NegatedIfElseCondition:
328
+ Enabled: true
329
+
330
+ Style/NestedFileDirname:
331
+ Enabled: true
332
+
333
+ Style/NestedParenthesizedCalls:
334
+ Enabled: false
335
+
336
+ Style/NilLambda:
337
+ Enabled: true
338
+
339
+ Style/NonNilCheck:
340
+ Enabled: false
341
+
342
+ Style/NumberedParameters:
343
+ Enabled: true
344
+ EnforcedStyle: disallow
345
+
346
+ Style/NumberedParametersLimit:
347
+ Enabled: true
348
+
349
+ Style/ObjectThen:
350
+ Enabled: true
351
+
352
+ Style/OpenStructUse:
353
+ Enabled: false
354
+
355
+ Style/OperatorMethodCall:
356
+ Enabled: true
357
+
358
+ Style/OptionHash:
359
+ Enabled: true
360
+
361
+ Style/QuotedSymbols:
362
+ Enabled: true
363
+
364
+ Style/RedundantArgument:
365
+ Enabled: false
366
+
367
+ Style/RedundantConstantBase:
368
+ Enabled: false
369
+
370
+ Style/RedundantDoubleSplatHashBraces:
371
+ Enabled: true
372
+
373
+ Style/RedundantEach:
374
+ Enabled: true
375
+
376
+ Style/RedundantException:
377
+ Enabled: false
378
+
379
+ Style/RedundantHeredocDelimiterQuotes:
380
+ Enabled: true
381
+
382
+ Style/RedundantInitialize:
383
+ Enabled: true
384
+
385
+ Style/RedundantParentheses:
386
+ Enabled: false
387
+
388
+ Style/RedundantSelfAssignmentBranch:
389
+ Enabled: true
390
+
391
+ Style/RedundantStringEscape:
392
+ Enabled: true
393
+
394
+ Style/RegexpLiteral:
395
+ EnforcedStyle: percent_r
396
+
397
+ Style/ReturnNil:
398
+ Enabled: true
399
+
400
+ Style/SelectByRegexp:
401
+ Enabled: true
402
+
403
+ Style/SingleLineMethods:
404
+ AllowIfMethodIsEmpty: false
405
+
406
+ Style/StaticClass:
407
+ Enabled: true
408
+
409
+ Style/StringChars:
410
+ Enabled: true
411
+
412
+ Style/StringHashKeys:
413
+ Enabled: false
414
+
415
+ Style/SwapValues:
416
+ Enabled: true
417
+
418
+ Style/SymbolArray:
419
+ EnforcedStyle: brackets
420
+
421
+ Style/TernaryParentheses:
422
+ EnforcedStyle: require_parentheses_when_complex
423
+ AllowSafeAssignment: false
424
+
425
+ Style/TopLevelMethodDefinition:
426
+ Enabled: true
427
+
428
+ Style/TrailingCommaInArguments:
429
+ Enabled: true
430
+ EnforcedStyleForMultiline: no_comma
431
+
432
+ Style/TrailingCommaInArrayLiteral:
433
+ Enabled: true
434
+ EnforcedStyleForMultiline: no_comma
435
+
436
+ Style/TrailingCommaInBlockArgs:
437
+ Enabled: true
438
+
439
+ Style/TrailingCommaInHashLiteral:
440
+ Enabled: true
441
+ EnforcedStyleForMultiline: no_comma
442
+
443
+ Style/UnlessLogicalOperators:
444
+ EnforcedStyle: forbid_logical_operators
445
+
446
+ Style/WordArray:
447
+ EnforcedStyle: brackets
448
+
449
+ Style/YodaCondition:
450
+ Enabled: true
451
+ EnforcedStyle: forbid_for_all_comparison_operators
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 2023-06-05
4
+
5
+ First release. Refer to [README.md](README.md) for the full documentation.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in therefore.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 13.0'
7
+
8
+ gem 'rubocop', '~> 1.21'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Moku S.r.l., Riccardo Agatea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # RedisJSON
2
+
3
+ A Ruby client for the [RedisJSON](https://redis.io/docs/stack/json/) module of the Redis Stack.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'redis-json', '~> 1.0'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or you can install the gem on its own:
20
+
21
+ ```bash
22
+ gem install redis-json
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ This gem builds on the [redis-rb](https://github.com/redis/redis-rb) gem. It add a `Redis#json` method, through which you can call the JSON-specific Redis commands:
28
+
29
+ ```ruby
30
+ redis = Redis.new
31
+
32
+ hash = {
33
+ number: 1,
34
+ string: 'example',
35
+ empty_object: {}
36
+ }
37
+ redis.json.set 'key', hash # => OK
38
+ ```
39
+
40
+ Input values will be converted to JSON strings using `JSON.generate`, and returned JSON strings will be parsed to Ruby objects using `JSON.parse`. You can use, respectively, `generate_options` and `parse_options` to specify options that will be passed on to the `JSON` methods:
41
+
42
+ ```ruby
43
+ r.json.get 'key'
44
+ # => {'number' => 10}
45
+
46
+ r.json.get 'key', parse_options: {symbolize_names: true}
47
+ # => {:number => 10}
48
+ ```
49
+
50
+ The methods are defined to be as similar as possible to the respective RedisJSON commands. `key` and `value` parameters become positional arguments, while more "option-like" parameters become keyword arguments (for example, the `NX` and `XX` parameters of the `JSON.SET` command become the `nx:` and `xx:` keyword arguments of the `set` method). The exception to this rule is `path`: to allow for the different combinations of default and variadic arguments, `path` is a keyword argument for all methods except `get` and `mset`.
51
+
52
+ ## Version numbers
53
+
54
+ RedisJSON loosely follows [Semantic Versioning](https://semver.org/), with a hard guarantee that breaking changes to the public API will always coincide with an increase to the `MAJOR` number.
55
+
56
+ Version numbers are in three parts: `MAJOR.MINOR.PATCH`.
57
+
58
+ - Breaking changes to the public API increment the `MAJOR`. There may also be changes that would otherwise increase the `MINOR` or the `PATCH`.
59
+ - Additions, deprecations, and "big" non breaking changes to the public API increment the `MINOR`. There may also be changes that would otherwise increase the `PATCH`.
60
+ - Bug fixes and "small" non breaking changes to the public API increment the `PATCH`.
61
+
62
+ Notice that any feature deprecated by a minor release can be expected to be removed by the next major release.
63
+
64
+ ## Changelog
65
+
66
+ Full list of changes in [CHANGELOG.md](CHANGELOG.md)
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/moku-io/redis-json.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+
7
+ task default: [:rubocop]
@@ -0,0 +1,259 @@
1
+ require 'json'
2
+
3
+ class Redis
4
+ module JSON
5
+ class Client
6
+ NOT_PROVIDED = ::Object.new
7
+ private_constant :NOT_PROVIDED
8
+
9
+ def initialize redis_client
10
+ @redis_client = redis_client
11
+ end
12
+
13
+ def call command, *args
14
+ redis_client.call [:"json.#{command}", *args]
15
+ end
16
+
17
+ def arrappend key, value, *values, path: NOT_PROVIDED, generate_options: {}
18
+ value = generate value, **generate_options
19
+ values.map! { |val| generate val, **generate_options }
20
+
21
+ if path.eql? NOT_PROVIDED
22
+ call __callee__, key, value, *values
23
+ else
24
+ call __callee__, key, path, value, *values
25
+ end
26
+ end
27
+
28
+ def arrindex key, value, start=NOT_PROVIDED, stop=NOT_PROVIDED, path:, generate_options: {}
29
+ value = generate value, **generate_options
30
+
31
+ if start.eql? NOT_PROVIDED
32
+ call __callee__, key, path, value
33
+ elsif stop.eql? NOT_PROVIDED
34
+ call __callee__, key, path, value, start
35
+ else
36
+ call __callee__, key, path, value, start, stop
37
+ end
38
+ end
39
+
40
+ def arrinsert key, index, value, *values, path:, generate_options: {}
41
+ value = generate value, **generate_options
42
+ values.map! { |val| generate val, **generate_options }
43
+
44
+ call __callee__, key, path, index, value, *values
45
+ end
46
+
47
+ def arrlen key, path: NOT_PROVIDED
48
+ if path.eql? NOT_PROVIDED
49
+ call __callee__, key
50
+ else
51
+ call __callee__, key, path
52
+ end
53
+ end
54
+
55
+ def arrpop key, index=NOT_PROVIDED, path: NOT_PROVIDED
56
+ if !index.eql?(NOT_PROVIDED) && path.eql?(NOT_PROVIDED)
57
+ raise ArgumentError,
58
+ 'You cannot specify an index unless you also specify a path'
59
+ end
60
+
61
+ if path.eql? NOT_PROVIDED
62
+ call __callee__, key
63
+ elsif index.eql? NOT_PROVIDED
64
+ call __callee__, key, path
65
+ else
66
+ call __callee__, key, path, index
67
+ end
68
+ end
69
+
70
+ def arrtrim key, start, stop, path:
71
+ call __callee__, key, path, start, stop
72
+ end
73
+
74
+ def clear key, path: NOT_PROVIDED
75
+ if path.eql? NOT_PROVIDED
76
+ call __callee__, key
77
+ else
78
+ call __callee__, key, path
79
+ end
80
+ end
81
+
82
+ def debug_memory key, path: NOT_PROVIDED
83
+ if path.eql? NOT_PROVIDED
84
+ call __callee__, key
85
+ else
86
+ call __callee__, key, path
87
+ end
88
+ end
89
+
90
+ def del key, path: NOT_PROVIDED
91
+ if path.eql? NOT_PROVIDED
92
+ call __callee__, key
93
+ else
94
+ call __callee__, key, path
95
+ end
96
+ end
97
+
98
+ def forget key, path: NOT_PROVIDED
99
+ if path.eql? NOT_PROVIDED
100
+ call __callee__, key
101
+ else
102
+ call __callee__, key, path
103
+ end
104
+ end
105
+
106
+ def get key, *paths, indent: NOT_PROVIDED, newline: NOT_PROVIDED, space: NOT_PROVIDED, parse_options: {}
107
+ options = {
108
+ indent: indent,
109
+ newline: newline,
110
+ space: space
111
+ }
112
+ options.reject! { |_name, value| value.eql?(NOT_PROVIDED) }
113
+ options.transform_keys!(&:upcase)
114
+
115
+ call(__callee__, key, *options.flatten, *paths)
116
+ .then do |response|
117
+ parse response, **parse_options if response
118
+ end
119
+ end
120
+
121
+ def merge key, value, path:, generate_options: {}
122
+ value = generate value, **generate_options
123
+
124
+ call __callee__, key, path, value
125
+ end
126
+
127
+ def mget key, *keys, path:, parse_options: {}
128
+ call(__callee__, key, *keys, path)
129
+ .map do |response|
130
+ parse response, **parse_options if response
131
+ end
132
+ end
133
+
134
+ def mset key, path, value, *rest, generate_options: {}
135
+ if rest.size % 3 != 0
136
+ raise ArgumentError,
137
+ 'mset requires parameters to be in triples <key, path, value>'
138
+ end
139
+
140
+ value = generate value, **generate_options
141
+ rest.map!.with_index do |item, index|
142
+ if index % 3 == 2
143
+ generate(item, **generate_options)
144
+ else
145
+ item
146
+ end
147
+ end
148
+
149
+ call __callee__, key, path, value, *rest
150
+ end
151
+
152
+ def numincrby key, value, path:, parse_options: {}
153
+ call(__callee__, key, path, value)
154
+ .then do |response|
155
+ parse response, **parse_options if response
156
+ end
157
+ end
158
+
159
+ def nummultby key, value, path:, parse_options: {}
160
+ call(__callee__, key, path, value)
161
+ .then do |response|
162
+ parse response, **parse_options if response
163
+ end
164
+ end
165
+
166
+ def numpowby key, value, path:, parse_options: {}
167
+ call(__callee__, key, path, value)
168
+ .then do |response|
169
+ parse response, **parse_options if response
170
+ end
171
+ end
172
+
173
+ def objkeys key, path: NOT_PROVIDED
174
+ if path.eql? NOT_PROVIDED
175
+ call __callee__, key
176
+ else
177
+ call __callee__, key, path
178
+ end
179
+ end
180
+
181
+ def objlen key, path: NOT_PROVIDED
182
+ if path.eql? NOT_PROVIDED
183
+ call __callee__, key
184
+ else
185
+ call __callee__, key, path
186
+ end
187
+ end
188
+
189
+ def resp key, path: NOT_PROVIDED
190
+ if path.eql? NOT_PROVIDED
191
+ call __callee__, key
192
+ else
193
+ call __callee__, key, path
194
+ end
195
+ end
196
+
197
+ # rubocop:disable Naming/MethodParameterName
198
+ def set key, value, path:, nx: NOT_PROVIDED, xx: NOT_PROVIDED, generate_options: {}
199
+ if !nx.eql?(NOT_PROVIDED) && !xx.eql?(NOT_PROVIDED)
200
+ raise ArgumentError,
201
+ 'NX and XX are mutually exclusive'
202
+ end
203
+
204
+ value = generate value, **generate_options
205
+
206
+ if !nx.eql?(NOT_PROVIDED)
207
+ call __callee__, key, path, value, :NX
208
+ elsif !xx.eql?(NOT_PROVIDED)
209
+ call __callee__, key, path, value, :XX
210
+ else
211
+ call __callee__, key, path, value
212
+ end
213
+ end
214
+ # rubocop:enable Naming/MethodParameterName
215
+
216
+ def strappend key, value, path: NOT_PROVIDED, generate_options: {}
217
+ value = generate value, **generate_options
218
+
219
+ if path.eql? NOT_PROVIDED
220
+ call __callee__, key, value
221
+ else
222
+ call __callee__, key, path, value
223
+ end
224
+ end
225
+
226
+ def strlen key, path: NOT_PROVIDED
227
+ if path.eql? NOT_PROVIDED
228
+ call __callee__, key
229
+ else
230
+ call __callee__, key, path
231
+ end
232
+ end
233
+
234
+ def toggle key, path:
235
+ call __callee__, key, path
236
+ end
237
+
238
+ def type key, path: NOT_PROVIDED
239
+ if path.eql? NOT_PROVIDED
240
+ call __callee__, key
241
+ else
242
+ call __callee__, key, path
243
+ end
244
+ end
245
+
246
+ private
247
+
248
+ attr_reader :redis_client
249
+
250
+ def generate object, **options
251
+ ::JSON.generate(object, **options)
252
+ end
253
+
254
+ def parse json_string, **options
255
+ ::JSON.parse(json_string, **options)
256
+ end
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'client'
2
+
3
+ class Redis
4
+ module Commands
5
+ def json
6
+ JSON::Client.new self
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ module JSON
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
data/lib/redis/json.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'redis'
2
+ require_relative 'json/version'
3
+ require_relative 'json/commands_patch'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Moku S.r.l.
8
+ - Riccardo Agatea
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: A Ruby client for the RedisJSON module of the Redis Stack.
29
+ email:
30
+ - info@moku.io
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/redis/json.rb
42
+ - lib/redis/json/client.rb
43
+ - lib/redis/json/commands_patch.rb
44
+ - lib/redis/json/version.rb
45
+ homepage: https://github.com/moku-io/redis-json
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/moku-io/redis-json
50
+ source_code_uri: https://github.com/moku-io/redis-json
51
+ changelog_uri: https://github.com/moku-io/redis-json/blob/master/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.4.6
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A Ruby client for the RedisJSON module of the Redis Stack.
71
+ test_files: []