protocol-redis 0.4.0 → 0.6.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.
@@ -1,6 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- indent_size = 2
6
-
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
13
- .covered.db
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --warnings
3
- --require spec_helper
@@ -1,22 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- services:
6
- - redis-server
7
-
8
- matrix:
9
- include:
10
- - rvm: 2.5
11
- - rvm: 2.6
12
- - rvm: 2.7
13
- - rvm: 2.6
14
- env: COVERAGE=BriefSummary,Coveralls
15
- - rvm: ruby-head
16
- - rvm: truffleruby
17
- - rvm: jruby-head
18
- env: JRUBY_OPTS="--debug -X+O"
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: truffleruby
22
- - rvm: jruby-head
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in async-io.gemspec
6
- gemspec
7
-
8
- group :development do
9
- gem 'pry'
10
- end
data/README.md DELETED
@@ -1,67 +0,0 @@
1
- # Protocol::Redis
2
-
3
- Implements the RESP2 and [RESP3](https://github.com/antirez/RESP3) Redis protocols.
4
-
5
- [![Build Status](https://travis-ci.com/socketry/protocol-redis.svg?branch=master)](https://travis-ci.com/socketry/protocol-redis)
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'protocol-redis'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install protocol-redis
22
-
23
- ## Usage
24
-
25
- ```ruby
26
- sockets = Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)
27
-
28
- client = Protocol::Redis::Connection.new(sockets.first)
29
- server = Protocol::Redis::Connection.new(sockets.last)
30
-
31
- client.write_object("Hello World!")
32
- puts server.read_object
33
- # => "Hello World!"
34
- ```
35
-
36
- ## Contributing
37
-
38
- 1. Fork it
39
- 2. Create your feature branch (`git checkout -b my-new-feature`)
40
- 3. Commit your changes (`git commit -am 'Add some feature'`)
41
- 4. Push to the branch (`git push origin my-new-feature`)
42
- 5. Create new Pull Request
43
-
44
- ## License
45
-
46
- Released under the MIT license.
47
-
48
- Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
49
- Copyright, 2019, by Huba Z. Nagy.
50
-
51
- Permission is hereby granted, free of charge, to any person obtaining a copy
52
- of this software and associated documentation files (the "Software"), to deal
53
- in the Software without restriction, including without limitation the rights
54
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55
- copies of the Software, and to permit persons to whom the Software is
56
- furnished to do so, subject to the following conditions:
57
-
58
- The above copyright notice and this permission notice shall be included in
59
- all copies or substantial portions of the Software.
60
-
61
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
67
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- Dir.glob('tasks/**/*.rake').each{|path| load(path)}
7
-
8
- RSpec::Core::RakeTask.new
9
-
10
- task :default => :spec
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- require 'benchmark/ips'
25
-
26
- GC.disable
27
-
28
- def call(*arguments)
29
- arguments.size
30
- end
31
-
32
- Benchmark.ips do |benchmark|
33
- benchmark.time = 5
34
- benchmark.warmup = 1
35
-
36
- benchmark.report("*arguments") do |count|
37
- while count > 0
38
- arguments = ["foo", "bar", "baz"]
39
- call(*arguments)
40
-
41
- count -= 1
42
- end
43
- end
44
-
45
- benchmark.report("argument, *arguments") do |count|
46
- while count > 0
47
- arguments = ["bar", "baz"]
48
- call("foo", *arguments)
49
-
50
- count -= 1
51
- end
52
- end
53
-
54
- benchmark.compare!
55
- end
@@ -1,28 +0,0 @@
1
-
2
- require_relative 'lib/protocol/redis/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "protocol-redis"
6
- spec.version = Protocol::Redis::VERSION
7
- spec.authors = ["Samuel Williams", "Huba Nagy"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz", "12huba@gmail.com"]
9
-
10
- spec.summary = "A RESP protocol client/server parser."
11
- spec.homepage = "https://github.com/socketry/protocol-redis"
12
-
13
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
- f.match(%r{^(test|spec|features)/})
15
- end
16
-
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_development_dependency "async-http"
21
- spec.add_development_dependency "trenni"
22
- spec.add_development_dependency "benchmark-ips"
23
-
24
- spec.add_development_dependency "covered"
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rspec", "~> 3.6"
27
- spec.add_development_dependency "rake"
28
- end
@@ -1,174 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- # Copyright, 2018, by Huba Nagy.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- require 'async'
25
-
26
- namespace :generate do
27
- def fetch_commands
28
- Async do
29
- internet = Async::HTTP::Internet.new
30
-
31
- response = internet.get("https://raw.githubusercontent.com/antirez/redis-doc/master/commands.json")
32
-
33
- JSON.parse(response.read, symbolize_names: true)
34
- ensure
35
- internet&.close
36
- end.wait
37
- end
38
-
39
- def normalize(sentence)
40
- return nil if sentence.nil?
41
-
42
- sentence = sentence.strip
43
-
44
- if sentence.end_with?(".")
45
- return sentence
46
- else
47
- return "#{sentence}."
48
- end
49
- end
50
-
51
- def module_name(group)
52
- group.split('_').collect(&:capitalize).join
53
- end
54
-
55
- task :commands do
56
- require 'async/http/internet'
57
- require 'json'
58
-
59
- @commands = fetch_commands
60
-
61
- @commands.each do |command, command_spec|
62
- method_name = command.to_s.downcase.split(/[\s\-_]+/).join('_')
63
- command_spec[:method_name] = method_name
64
- end
65
-
66
- # There is a bit of a discrepancy between how the groups appear in the JSON and how they appear in the compiled documentation, this is a mapping from `commands.json` to documentation:
67
- @groups = {
68
- 'generic' => 'generic',
69
- 'string' => 'strings',
70
- 'list' => 'lists',
71
- 'set' => 'sets',
72
- 'sorted_set' => 'sorted_sets',
73
- 'hash' => 'hashes',
74
- 'connection' => 'connection',
75
- 'server' => 'server',
76
- 'scripting' => 'scripting',
77
- 'hyperloglog' => 'counting',
78
- 'cluster' => 'cluster',
79
- 'geo' => 'geospatial',
80
- 'stream' => 'streams'
81
- }.freeze
82
- end
83
-
84
- task :methods => :commands do
85
- require 'trenni/template'
86
-
87
- template = Trenni::Template.load_file(File.expand_path("methods.trenni", __dir__))
88
-
89
- @groups.each_pair do |spec_group, group|
90
- puts "Processing #{spec_group}..."
91
-
92
- path = "lib/protocol/redis/methods/#{group}.rb"
93
-
94
- if File.exist?(path)
95
- puts "File already exists #{path}, skipping!"
96
- next
97
- end
98
-
99
- group_commands = @commands.select do |command, command_spec|
100
- command_spec[:group] == spec_group
101
- end
102
-
103
- output = template.to_string({
104
- module_name: module_name(group),
105
- group_commands: group_commands,
106
- })
107
-
108
- File.write(path, output)
109
-
110
- break
111
- end
112
- end
113
-
114
- task :documentation => :commands do
115
- @groups.each_pair do |spec_group, group|
116
- puts "Processing #{spec_group}..."
117
-
118
- path = "lib/protocol/redis/methods/#{group}.rb"
119
-
120
- unless File.exist?(path)
121
- puts "Could not find #{path}, skipping!"
122
- next
123
- end
124
-
125
- lines = File.readlines(path)
126
-
127
- group_commands = @commands.select do |command, command_spec|
128
- command_spec[:group] == spec_group
129
- end
130
-
131
- puts "\tFound #{group_commands.length} commands in this group."
132
-
133
- group_commands.each do |command, command_spec|
134
- puts "\tProcessing #{command}..."
135
-
136
- if offset = lines.find_index{|line| line.include?("def #{command_spec[:method_name]}")}
137
- puts "Found #{command} at line #{offset}."
138
-
139
- /(?<indentation>\s+)def/ =~ lines[offset]
140
-
141
- start = offset
142
- while true
143
- break unless lines[start-1] =~ /\s+#(.*?)\n/
144
- start -= 1
145
- end
146
-
147
- # Remove the comments:
148
- lines.slice!(start...offset)
149
-
150
- summary = [
151
- normalize(command_spec[:summary]),
152
- normalize(command_spec[:complexity])
153
- ].compact
154
-
155
- comments = [
156
- summary.join(' '),
157
- "@see https://redis.io/commands/#{command.to_s.downcase}"
158
- ]
159
-
160
- command_spec[:arguments]&.each do |argument|
161
- next if argument[:command] or argument[:type].nil? or argument[:type].is_a?(Array)
162
- comments << "@param #{argument[:name]} [#{argument[:type].capitalize}]"
163
- end
164
-
165
- lines.insert(start, comments.map{|comment| "#{indentation}\# #{comment}\n"})
166
- else
167
- puts "Could not find #{command} definition!"
168
- end
169
- end
170
-
171
- File.write(path, lines.join)
172
- end
173
- end
174
- end