rejson-rb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd7a76d54e046c3ba8880b0aaeb7d3df2849b95aad7d5097c321b46d3d82844a
4
+ data.tar.gz: 371f4e666bb970f311e24cc9b571ba75a76d16d67fd3fe7c5470c85a512538af
5
+ SHA512:
6
+ metadata.gz: 36a5c940c8efe4c9da419fb23abfdaa5b472bbbc2b87ede905fb74a371d29ab7591c150b43c801cecea8a5b26d78d220594f2dcc28e6fbe3abc82dbcf3aa6ae1
7
+ data.tar.gz: 3fafa39182f902bcaf469738666da400ba87258c03dbeec3a4426fc4e47687c337a4d06dacd1377cb0bd2a35e77bb5e66366ddbd1700b380346278fc4c794d6f
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ .idea/
11
+ .vscode/
12
+ .rspec_status
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.5
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.0
8
+
9
+ install:
10
+ # Get Redis
11
+ - git clone --depth=1 https://github.com/antirez/redis.git && cd redis && make && cd ..
12
+ # Get ReJSON
13
+ - git clone --depth=1 https://github.com/RedisLabsModules/ReJSON.git && cd ReJSON && make && cd ..
14
+ # Install dependency gems
15
+ - bundle install
16
+
17
+ before_script:
18
+ - ./redis/src/redis-server --loadmodule ReJSON/src/rejson.so &
19
+ - bundle install
20
+
21
+ script:
22
+ - bundle exec rspec
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at vachhanihpavan@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rejson-rb.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 12.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Pavan Vachhani
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.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # RedisJSON Ruby Client [![Build Status](https://travis-ci.com/vachhanihpavan/rejson-rb.svg?token=x85KXUqPs5qJik1EzpyW&branch=master)](https://travis-ci.com/vachhanihpavan/rejson-rb)
2
+
3
+ rejson-rb is a package that allows storing, updating and querying objects as JSON documents in a [Redis](https://redis.io/) database that is extended with the [ReJSON](https://github.com/RedisJSON/RedisJSON) module. The package extends redis-rb's interface with ReJSON's API, and performs on-the-fly serialization/deserialization of objects to/from JSON.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rejson-rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rejson-rb
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vachhanihpavan/rejson-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/vachhanihpavan/rejson-rb/blob/master/CODE_OF_CONDUCT.md).
24
+
25
+ For complete documentation about ReJSON's commands, refer to ReJSON's website.
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
29
+
30
+ ## Code of Conduct
31
+
32
+ Everyone interacting in the Rejson::Rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vachhanihpavan/rejson-rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => :spec
11
+ rescue LoadError
12
+ # no rspec available
13
+ end
14
+
15
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rejson/rb"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/lib/rejson.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rejson/version"
4
+ require "rejson/path"
5
+ require "rejson/client"
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis"
4
+ require "json"
5
+
6
+ # Extends Redis class to add JSON functions
7
+ class Redis
8
+ def json_set(key, path, data, options = {})
9
+ pieces = [key, str_path(path), json_encode(data)]
10
+ options[:nx] ||= false if options.dig(:nx)
11
+
12
+ options[:xx] ||= false if options.dig(:xx)
13
+
14
+ if options[:nx] && options[:xx]
15
+ raise Exception, "nx and xx are mutually exclusive: use one, the other or neither - but not both"
16
+ elsif options[:nx]
17
+ pieces.append("NX")
18
+ elsif options[:xx]
19
+ pieces.append("XX")
20
+ end
21
+
22
+ call_client(:set, pieces)
23
+ end
24
+
25
+ def json_get(key, *args)
26
+ pieces = [key]
27
+
28
+ if args.empty?
29
+ pieces.append(str_path(Rejson::Path.root_path))
30
+ else
31
+ args.each do |arg|
32
+ pieces.append(str_path(arg))
33
+ end
34
+ end
35
+
36
+ begin
37
+ json_decode call_client(:get, pieces)
38
+ rescue TypeError
39
+ nil
40
+ end
41
+ end
42
+
43
+ def json_mget(key, *args)
44
+ pieces = [key]
45
+
46
+ if args.empty?
47
+ raise ArgumentError "Invalid arguments"
48
+ else
49
+ pieces.append(args)
50
+ end
51
+
52
+ json_bulk_decode call_client(:mget, pieces)
53
+ end
54
+
55
+ def json_del(key, *args)
56
+ pieces = [key]
57
+ pieces.append(str_path(args))
58
+ call_client(:del, pieces).to_i
59
+ end
60
+
61
+ alias json_forget json_del
62
+
63
+ def json_type(key, *args)
64
+ pieces = [key]
65
+ pieces.append(str_path(args))
66
+ call_client(:type, pieces).to_s
67
+ end
68
+
69
+ def json_numincrby(key, path, number)
70
+ pieces = [key, str_path(path), number]
71
+ call_client(:numincrby, pieces).to_i
72
+ end
73
+
74
+ def json_nummultby(key, path, number)
75
+ pieces = [key, str_path(path), number]
76
+ call_client(:nummultby, pieces).to_i
77
+ end
78
+
79
+ def json_strappend(key, string, path = Rejson::Path.root_path)
80
+ pieces = [key, str_path(path), json_encode(string)]
81
+ call_client(:strappend, pieces).to_i
82
+ end
83
+
84
+ def json_strlen(key, path = Rejson::Path.root_path)
85
+ pieces = [key, str_path(path)]
86
+ call_client(:strlen, pieces).to_i
87
+ end
88
+
89
+ def json_arrappend(key, path, json, *args)
90
+ json_objs = [json_encode(json)]
91
+ args.each { |arg| json_objs.append(json_encode(arg)) }
92
+ pieces = [key, str_path(path), json_objs]
93
+ call_client(:arrappend, pieces).to_i
94
+ end
95
+
96
+ def json_arrindex(key, path, scalar, start = 0, stop = 0)
97
+ pieces = [key, str_path(path), scalar, start, stop]
98
+ call_client(:arrindex, pieces).to_i
99
+ end
100
+
101
+ def json_arrinsert(key, path, index, *args)
102
+ json_objs = []
103
+ args.each { |arg| json_objs.append(json_encode(arg)) }
104
+ pieces = [key, str_path(path), index, json_objs]
105
+ call_client(:arrinsert, pieces).to_i
106
+ end
107
+
108
+ def json_arrlen(key, path = Rejson::Path.root_path)
109
+ pieces = [key, str_path(path)]
110
+ call_client(:arrlen, pieces).to_i
111
+ end
112
+
113
+ def json_arrpop(key, path = Rejson::Path.root_path, index = -1)
114
+ pieces = [key, str_path(path), index]
115
+ call_client(:arrpop, pieces).to_s
116
+ end
117
+
118
+ def json_arrtrim(key, path, start, stop)
119
+ pieces = [key, str_path(path), start, stop]
120
+ call_client(:arrtrim, pieces).to_i
121
+ end
122
+
123
+ def json_objkeys(key, path = Rejson::Path.root_path)
124
+ pieces = [key, str_path(path)]
125
+ call_client(:objkeys, pieces).to_a
126
+ end
127
+
128
+ def json_objlen(key, path = Rejson::Path.root_path)
129
+ pieces = [key, str_path(path)]
130
+ call_client(:objlen, pieces).to_i
131
+ end
132
+
133
+ def json_resp(key, path = Rejson::Path.root_path)
134
+ pieces = [key, str_path(path)]
135
+ call_client(:resp, pieces)
136
+ end
137
+
138
+ private
139
+
140
+ def str_path(p)
141
+ if p.instance_of?(Rejson::Path)
142
+ p.str_path
143
+ else
144
+ p
145
+ end
146
+ end
147
+
148
+ def json_encode(obj)
149
+ JSON.generate(obj)
150
+ end
151
+
152
+ def json_decode(obj)
153
+ JSON.parse(obj)
154
+ end
155
+
156
+ def json_bulk_decode(obj)
157
+ res = []
158
+ obj.to_a.each do |o|
159
+ if o.nil?
160
+ res.append(nil)
161
+ else
162
+ res.append(JSON.parse(o))
163
+ end
164
+ end
165
+ res
166
+ end
167
+
168
+ def call_client(cmd, pieces)
169
+ pieces.prepend("JSON.#{cmd.upcase}").join(" ")
170
+ client.call pieces
171
+ end
172
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rejson
4
+ # Represents a Path in JSON value
5
+ class Path
6
+ attr_accessor :str_path
7
+
8
+ def self.root_path
9
+ root = Path.new(".")
10
+ root
11
+ end
12
+
13
+ def initialize(path)
14
+ @str_path = path
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rejson
4
+ VERSION = "1.0.0"
5
+ end
data/rejson-rb.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/rejson/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rejson-rb"
7
+ spec.version = Rejson::VERSION
8
+ spec.authors = ["Pavan Vachhani"]
9
+ spec.email = ["vachhanihpavan@gmail.com"]
10
+
11
+ spec.summary = "Redis JSON Ruby Client"
12
+ spec.description = "rejson-rb is a package that allows storing, updating and querying objects as JSON documents in Redis database that is intended with RedisJSON module."
13
+ spec.homepage = "https://github.com/vachhanihpavan/rejson-rb"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/vachhanihpavan/rejson-rb"
19
+ spec.metadata["changelog_uri"] = "https://github.com/vachhanihpavan/rejson-rb"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "redis", "~> 3.0"
31
+ spec.add_runtime_dependency "json", "~> 2.0"
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "simplecov","~> 0.17"
35
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rejson-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavan Vachhani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-23 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
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
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.17'
83
+ description: rejson-rb is a package that allows storing, updating and querying objects
84
+ as JSON documents in Redis database that is intended with RedisJSON module.
85
+ email:
86
+ - vachhanihpavan@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/rejson.rb
101
+ - lib/rejson/client.rb
102
+ - lib/rejson/path.rb
103
+ - lib/rejson/version.rb
104
+ - rejson-rb.gemspec
105
+ homepage: https://github.com/vachhanihpavan/rejson-rb
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://github.com/vachhanihpavan/rejson-rb
110
+ source_code_uri: https://github.com/vachhanihpavan/rejson-rb
111
+ changelog_uri: https://github.com/vachhanihpavan/rejson-rb
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.3.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Redis JSON Ruby Client
131
+ test_files: []