protocol-redis 0.5.0 → 0.8.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/redis/connection.rb +2 -19
- data/lib/protocol/redis/error.rb +2 -19
- data/lib/protocol/redis/methods/cluster.rb +30 -0
- data/lib/protocol/redis/methods/connection.rb +6 -22
- data/lib/protocol/redis/methods/counting.rb +2 -19
- data/lib/protocol/redis/methods/generic.rb +11 -20
- data/lib/protocol/redis/methods/geospatial.rb +2 -19
- data/lib/protocol/redis/methods/hashes.rb +74 -27
- data/lib/protocol/redis/methods/lists.rb +3 -20
- data/lib/protocol/redis/methods/pubsub.rb +20 -0
- data/lib/protocol/redis/methods/scripting.rb +10 -51
- data/lib/protocol/redis/methods/server.rb +4 -21
- data/lib/protocol/redis/methods/sets.rb +2 -19
- data/lib/protocol/redis/methods/sorted_sets.rb +2 -19
- data/lib/protocol/redis/methods/streams.rb +2 -19
- data/lib/protocol/redis/methods/strings.rb +2 -20
- data/lib/protocol/redis/methods.rb +18 -20
- data/lib/protocol/redis/version.rb +3 -20
- data/lib/protocol/redis.rb +2 -19
- data/license.md +29 -0
- data/readme.md +50 -0
- data.tar.gz.sig +0 -0
- metadata +55 -124
- metadata.gz.sig +0 -0
- data/.editorconfig +0 -6
- data/.github/workflows/development.yml +0 -34
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/Gemfile +0 -10
- data/README.md +0 -67
- data/Rakefile +0 -10
- data/benchmark/call.rb +0 -55
- data/protocol-redis.gemspec +0 -27
- data/tasks/generate.rake +0 -174
- data/tasks/methods.trenni +0 -46
data/benchmark/call.rb
DELETED
@@ -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
|
data/protocol-redis.gemspec
DELETED
@@ -1,27 +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 transport agnostic RESP protocol client/server."
|
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.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_development_dependency "async-http"
|
20
|
-
spec.add_development_dependency "trenni"
|
21
|
-
spec.add_development_dependency "benchmark-ips"
|
22
|
-
|
23
|
-
spec.add_development_dependency "covered"
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.6"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
end
|
data/tasks/generate.rake
DELETED
@@ -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
|
data/tasks/methods.trenni
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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.
|
22
|
-
|
23
|
-
module Protocol
|
24
|
-
module Redis
|
25
|
-
module Methods
|
26
|
-
module #{self[:module_name]}
|
27
|
-
<?r
|
28
|
-
first = true
|
29
|
-
self[:group_commands].each do |command, command_spec|
|
30
|
-
method_name = command.to_s.downcase.split(/[\s\-_]+/).join('_')
|
31
|
-
|
32
|
-
unless first
|
33
|
-
?>
|
34
|
-
|
35
|
-
<?r end ?>
|
36
|
-
def #{method_name}(*arguments)
|
37
|
-
call(#{command.to_s.dump}, *arguments)
|
38
|
-
end
|
39
|
-
<?r
|
40
|
-
first = false
|
41
|
-
end
|
42
|
-
?>
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|