em-redis-unified 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +22 -0
- data/README.rdoc +86 -0
- data/Rakefile +41 -0
- data/lib/em-redis.rb +47 -0
- data/lib/em-redis/redis_protocol.rb +511 -0
- data/spec/live_redis_protocol_spec.rb +539 -0
- data/spec/redis_commands_spec.rb +664 -0
- data/spec/redis_protocol_spec.rb +143 -0
- data/spec/test_helper.rb +22 -0
- metadata +104 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
|
2
|
+
|
3
|
+
EM.describe EM::Protocols::Redis do
|
4
|
+
default_timeout 1
|
5
|
+
|
6
|
+
before do
|
7
|
+
@c = TestConnection.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# Inline request protocol
|
11
|
+
should 'send inline commands correctly' do
|
12
|
+
@c.call_command(["GET", 'a'])
|
13
|
+
@c.sent_data.should == "*2\r\n$3\r\nget\r\n$1\r\na\r\n"
|
14
|
+
done
|
15
|
+
end
|
16
|
+
|
17
|
+
should "space-separate multiple inline arguments" do
|
18
|
+
@c.call_command(["GET", 'a', 'b', 'c'])
|
19
|
+
@c.sent_data.should == "*4\r\n$3\r\nget\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n"
|
20
|
+
done
|
21
|
+
end
|
22
|
+
|
23
|
+
# Multiline request protocol
|
24
|
+
should "send multiline commands correctly" do
|
25
|
+
@c.call_command(["SET", "foo", "abc"])
|
26
|
+
@c.sent_data.should == "*3\r\n$3\r\nset\r\n$3\r\nfoo\r\n$3\r\nabc\r\n"
|
27
|
+
done
|
28
|
+
end
|
29
|
+
|
30
|
+
should "send integers in multiline commands correctly" do
|
31
|
+
@c.call_command(["SET", "foo", 1_000_000])
|
32
|
+
@c.sent_data.should == "*3\r\n$3\r\nset\r\n$3\r\nfoo\r\n$7\r\n1000000\r\n"
|
33
|
+
done
|
34
|
+
end
|
35
|
+
|
36
|
+
# Specific calls
|
37
|
+
#
|
38
|
+
# SORT
|
39
|
+
should "send sort command" do
|
40
|
+
@c.sort "foo"
|
41
|
+
@c.sent_data.should == "*2\r\n$4\r\nsort\r\n$3\r\nfoo\r\n"
|
42
|
+
done
|
43
|
+
end
|
44
|
+
|
45
|
+
should "send sort command with all optional parameters" do
|
46
|
+
@c.sort "foo", :by => "foo_sort_*", :get => "data_*", :order => "DESC ALPHA", :limit => [0, 10]
|
47
|
+
expected = "*11\r\n$4\r\nsort\r\n$3\r\nfoo\r\n$2\r\nby\r\n$10\r\nfoo_sort_*\r\n$3\r\nget\r\n"
|
48
|
+
expected += "$6\r\ndata_*\r\n$4\r\nDESC\r\n$5\r\nALPHA\r\n$5\r\nlimit\r\n$1\r\n0\r\n$2\r\n10\r\n"
|
49
|
+
@c.sent_data.should == expected
|
50
|
+
done
|
51
|
+
end
|
52
|
+
|
53
|
+
should "parse keys response into an array" do
|
54
|
+
@c.keys("*") do |resp|
|
55
|
+
resp.should == ["a","b","c"]
|
56
|
+
done
|
57
|
+
end
|
58
|
+
@c.receive_data "*3\r\n$1\r\na\r\n$1\r\nb\r\n$1\r\nc\r\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Inline response
|
63
|
+
should "parse an inline response" do
|
64
|
+
@c.call_command(["PING"]) do |resp|
|
65
|
+
resp.should == "OK"
|
66
|
+
done
|
67
|
+
end
|
68
|
+
@c.receive_data "+OK\r\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
should "parse an inline integer response" do
|
72
|
+
@c.call_command(["integer"]) do |resp|
|
73
|
+
resp.should == 0
|
74
|
+
done
|
75
|
+
end
|
76
|
+
@c.receive_data ":0\r\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
should "call processor if any" do
|
80
|
+
@c.call_command(["EXISTS"]) do |resp|
|
81
|
+
resp.should == false
|
82
|
+
done
|
83
|
+
end
|
84
|
+
@c.receive_data ":0\r\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
should "trigger a given error callback (specified with on_error) for inline error response instead of raising an error" do
|
88
|
+
lambda do
|
89
|
+
@c.call_command(["blarg"])
|
90
|
+
@c.on_error {|err| err.code.should == "ERR"; done }
|
91
|
+
@c.receive_data "-ERR\r\n"
|
92
|
+
end.should.not.raise(EM::P::Redis::RedisError)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "trigger a given error callback for inline error response instead of raising an error" do
|
96
|
+
lambda do
|
97
|
+
@c.call_command(["blarg"])
|
98
|
+
@c.errback { |err| err.code.should == "ERR"; done }
|
99
|
+
@c.receive_data "-ERR\r\n"
|
100
|
+
end.should.not.raise(EM::P::Redis::RedisError)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Bulk response
|
104
|
+
should "parse a bulk response" do
|
105
|
+
@c.call_command(["GET", "foo"]) do |resp|
|
106
|
+
resp.should == "bar"
|
107
|
+
done
|
108
|
+
end
|
109
|
+
@c.receive_data "$3\r\n"
|
110
|
+
@c.receive_data "bar\r\n"
|
111
|
+
end
|
112
|
+
|
113
|
+
should "distinguish nil in a bulk response" do
|
114
|
+
@c.call_command(["GET", "bar"]) do |resp|
|
115
|
+
resp.should == nil
|
116
|
+
done
|
117
|
+
end
|
118
|
+
@c.receive_data "$-1\r\n"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Multi-bulk response
|
122
|
+
should "parse a multi-bulk response" do
|
123
|
+
@c.call_command(["RANGE", 0, 10]) do |resp|
|
124
|
+
resp.should == ["a", "b", "foo"]
|
125
|
+
done
|
126
|
+
end
|
127
|
+
@c.receive_data "*3\r\n"
|
128
|
+
@c.receive_data "$1\r\na\r\n"
|
129
|
+
@c.receive_data "$1\r\nb\r\n"
|
130
|
+
@c.receive_data "$3\r\nfoo\r\n"
|
131
|
+
end
|
132
|
+
|
133
|
+
should "distinguish nil in a multi-bulk response" do
|
134
|
+
@c.call_command(["RANGE", 0, 10]) do |resp|
|
135
|
+
resp.should == ["a", nil, "foo"]
|
136
|
+
done
|
137
|
+
end
|
138
|
+
@c.receive_data "*3\r\n"
|
139
|
+
@c.receive_data "$1\r\na\r\n"
|
140
|
+
@c.receive_data "$-1\r\n"
|
141
|
+
@c.receive_data "$3\r\nfoo\r\n"
|
142
|
+
end
|
143
|
+
end
|
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/em-redis")
|
2
|
+
require 'bacon'
|
3
|
+
require 'em-spec/bacon'
|
4
|
+
|
5
|
+
EM.spec_backend = EventMachine::Spec::Bacon
|
6
|
+
|
7
|
+
class TestConnection
|
8
|
+
include EM::P::Redis
|
9
|
+
|
10
|
+
def send_data data
|
11
|
+
sent_data << data
|
12
|
+
end
|
13
|
+
|
14
|
+
def sent_data
|
15
|
+
@sent_data ||= ''
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
connection_completed
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-redis-unified
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Broad
|
9
|
+
- Eugene Pimenov
|
10
|
+
- Sean Porter
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: eventmachine
|
18
|
+
requirement: &14093880 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.12.10
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *14093880
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bacon
|
29
|
+
requirement: &14093420 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.2.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *14093420
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: em-spec
|
40
|
+
requirement: &14093000 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.2.6
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *14093000
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bones
|
51
|
+
requirement: &14092580 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.8.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *14092580
|
60
|
+
description: An eventmachine-based implementation of the Redis protocol
|
61
|
+
email: portertech@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files:
|
65
|
+
- History.txt
|
66
|
+
- README.rdoc
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- History.txt
|
70
|
+
- README.rdoc
|
71
|
+
- Rakefile
|
72
|
+
- lib/em-redis.rb
|
73
|
+
- lib/em-redis/redis_protocol.rb
|
74
|
+
- spec/live_redis_protocol_spec.rb
|
75
|
+
- spec/redis_commands_spec.rb
|
76
|
+
- spec/redis_protocol_spec.rb
|
77
|
+
- spec/test_helper.rb
|
78
|
+
homepage: http://github.com/portertech/em-redis
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project: em-redis-unified
|
100
|
+
rubygems_version: 1.8.11
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: An eventmachine-based implementation of the Redis protocol
|
104
|
+
test_files: []
|