redis_rejson 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0603ab2c6eda5d005f6f095b0f523e61b3bc9635e871a7113d5f12bd035fa825
4
+ data.tar.gz: 9b4e72504e4675554b44586349c37da4f6d86b96b203ccc3c4baf5c82192beba
5
+ SHA512:
6
+ metadata.gz: 85d75fdb8d4cd1b7669dcd389bb293d0d2e55be458460e723c0164d323a1fd04d889defb57fe4b0b20da1f5bfbf540bee966738a2dab56ba0490ba77917be0f1
7
+ data.tar.gz: e8f743026d041088288a26195a1bbe339f8861cc7a5ac5844eb7fcbfba324986c20091c0322d4f5350bf0122034607841c601a2a1043a862f376af2f901bfafa
@@ -0,0 +1,3 @@
1
+ dump.rdb
2
+ .rspec_status
3
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis_rejson.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redis_rejson (0.2.0)
5
+ redis (~> 3.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (12.3.3)
12
+ redis (3.3.3)
13
+ rspec (3.6.0)
14
+ rspec-core (~> 3.6.0)
15
+ rspec-expectations (~> 3.6.0)
16
+ rspec-mocks (~> 3.6.0)
17
+ rspec-core (3.6.0)
18
+ rspec-support (~> 3.6.0)
19
+ rspec-expectations (3.6.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-mocks (3.6.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.6.0)
25
+ rspec-support (3.6.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 2.1.4)
32
+ rake (~> 12.3.3)
33
+ redis_rejson!
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 makevoid
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # RedisRejson
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redis_rejson`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'redis_rejson'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install redis_rejson
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/redis_rejson.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,54 @@
1
+ # Redis ReJSON
2
+
3
+ Redis ReJSON (v4 Module - json manipulation) adapter for Ruby's Redis-rb - WIP
4
+
5
+ #### Installation
6
+
7
+ Compile the ReJSON module - configure redis (you need v4) to load it ( loadmodule /etc/redis/modules/rejson/rejson.so in `redis.conf` )
8
+
9
+
10
+ Documentation of ReJSON - https://redislabsmodules.github.io/rejson/commands/#jsonstrlen
11
+
12
+ ---
13
+
14
+ ## API:
15
+
16
+ ```rb
17
+ R = Redis.new(db: 14)
18
+
19
+ R.json_get "foo" # => "bar"
20
+
21
+ R.json_set "foo", '"baz"' # => "OK"
22
+
23
+ R.json_get "foo", p: "." # every command comes with *path selectors* support (you can traverse json arrays and objects and set child values - . is the root)
24
+
25
+ R.json_type "foo" # => "string" # returns the ype of the value at the given key
26
+
27
+ R.json_str_len "foo" # => 3
28
+
29
+ ```
30
+
31
+ else, check the specs ( https://github.com/makevoid/redis-rejson-rb/blob/master/spec/redis_rejson_spec.rb ) or the implementation itself (super simple atm)
32
+
33
+ ---
34
+
35
+ Soon:
36
+
37
+ ```
38
+ gem "redis_rejson"
39
+ ```
40
+
41
+ ---
42
+
43
+ wip
44
+
45
+ - key/value
46
+ - num
47
+ - strings
48
+ - ...
49
+
50
+ next:
51
+
52
+ - arrays
53
+ - objects
54
+ - etc
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "redis_rejson"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1 @@
1
+ docker run -p 6379:6379 redislabs/rejson:latest
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,107 @@
1
+ require 'redis'
2
+ require_relative "redis_rejson/version"
3
+
4
+ class Redis
5
+
6
+ module ReJSON
7
+ end
8
+
9
+ # key
10
+
11
+ def json_set(key, value, p: nil)
12
+ client.call json_cmd_two(:set, key, value, p)
13
+ end
14
+
15
+ def json_get(key, p: nil)
16
+ client.call json_cmd_one(:get, key, p)
17
+ end
18
+
19
+ def json_type(key, p: nil)
20
+ client.call json_cmd_one(:type, key, p)
21
+ end
22
+
23
+ def json_mget(key, p: nil)
24
+
25
+ end
26
+
27
+ # string
28
+
29
+ def json_str_len(key, p: nil)
30
+ client.call json_cmd_one(:strlen, key, p)
31
+ end
32
+
33
+ def json_str_append(key, value, p: nil)
34
+ client.call json_cmd_two(:strappend, key, value, p)
35
+ end
36
+
37
+ # num
38
+
39
+ def json_num_incr_by(key, value, p: nil)
40
+ jto_i client.call json_cmd_two(:numincrby, key, value, p)
41
+ end
42
+
43
+ def json_num_incr(key, p: nil)
44
+ jto_i client.call json_cmd_two(:numincrby, key, 1, p)
45
+ end
46
+
47
+ def json_num_mult_by(key, value, p: nil)
48
+ jto_i client.call json_cmd_two(:nummultby, key, value, p)
49
+ end
50
+
51
+ def json_num_mult_double(key, p: nil)
52
+ jto_i client.call json_cmd_two(:nummultby, key, 2, p)
53
+ end
54
+
55
+
56
+ # array
57
+
58
+ def json_arr_append(key, value, p: nil)
59
+ jto_i client.call json_cmd_two(:arrappend, key, value, p)
60
+ end
61
+
62
+ def json_arr_index(key, value, p: nil)
63
+ jto_i client.call json_cmd_two(:arrindex, key, value, p)
64
+ end
65
+
66
+ def json_arr_insert(key, value, p: nil)
67
+ jto_i client.call json_cmd_two(:arrinsert, key, value, p)
68
+ end
69
+
70
+ def json_arr_len(key, value, p: nil)
71
+ jto_i client.call json_cmd_two(:arrlen, key, value, p)
72
+ end
73
+
74
+ # object
75
+
76
+ # util
77
+
78
+ private
79
+
80
+ def jto_i(value)
81
+ value.to_i
82
+ end
83
+
84
+ # json command, one parameter
85
+ def json_cmd_one(cmd, key, path)
86
+ unless path
87
+ ["JSON.#{cmd.upcase}", key]
88
+ else
89
+ ["JSON.#{cmd.upcase}", key, path]
90
+ end
91
+ end
92
+
93
+ # json command, two parameters
94
+ def json_cmd_two(cmd, key, value, path)
95
+ unless path
96
+ ["JSON.#{cmd.upcase}", key, ".", value]
97
+ else
98
+ ["JSON.#{cmd.upcase}", key, path, value]
99
+ end
100
+ end
101
+
102
+ end
103
+ #
104
+ # redis.client.call(["JSON.SET", "foo", ".", "\"bar\""])
105
+ # => "OK"
106
+ #
107
+ # irb(main):012:0> redis.client.call(["JSON.GET", "foo"])
@@ -0,0 +1,3 @@
1
+ module RedisRejson
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis_rejson/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redis_rejson"
8
+ spec.version = RedisRejson::VERSION
9
+ spec.authors = ["makevoid"]
10
+ spec.email = ["makevoid@gmail.com"]
11
+
12
+ spec.summary = %q{Redis ReJSON adapter}
13
+ spec.description = %q{Redis ReJSON (v4 Module - json manipulation) API adapter}
14
+ spec.homepage = "https://github.com/makevoid/redis-rejson-rb"
15
+ spec.license = "Unlicense"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "redis", "~> 3.3"
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.1.4"
27
+ spec.add_development_dependency "rake", "~> 12.3.3"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_rejson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - makevoid
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 12.3.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Redis ReJSON (v4 Module - json manipulation) API adapter
70
+ email:
71
+ - makevoid@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README-autogen.md
81
+ - Rakefile
82
+ - Readme.md
83
+ - bin/console
84
+ - bin/redis-rejson-docker
85
+ - bin/setup
86
+ - lib/redis_rejson.rb
87
+ - lib/redis_rejson/version.rb
88
+ - redis_rejson.gemspec
89
+ homepage: https://github.com/makevoid/redis-rejson-rb
90
+ licenses:
91
+ - Unlicense
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Redis ReJSON adapter
112
+ test_files: []