superfeedr-em-redis 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-redis/redis_protocol.rb +28 -81
- data/lib/em-redis/version.rb +3 -0
- data/lib/em-redis.rb +2 -47
- metadata +21 -68
- data/README.rdoc +0 -85
- data/Rakefile +0 -41
- data/dump.rdb +0 -0
- data/spec/live_redis_protocol_spec.rb +0 -446
- data/spec/redis_commands_spec.rb +0 -754
- data/spec/redis_commands_spec.rb.orig +0 -731
- data/spec/redis_protocol_spec.rb +0 -149
- data/spec/test_helper.rb +0 -26
data/spec/redis_protocol_spec.rb
DELETED
@@ -1,149 +0,0 @@
|
|
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 == "get a\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 == "get a b c\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 == "set foo 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 == "set foo 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 == "sort foo\r\n"
|
42
|
-
done
|
43
|
-
end
|
44
|
-
|
45
|
-
should "send sort command with all optional parameters" do
|
46
|
-
@c.sort "foo", :by => "foo_sort_*", :limit => [0, 10], :get => "data_*", :order => "DESC ALPHA"
|
47
|
-
@c.sent_data.should == "sort foo BY foo_sort_* GET data_* DESC ALPHA LIMIT 0 10\r\n"
|
48
|
-
done
|
49
|
-
end
|
50
|
-
|
51
|
-
should "parse keys response into an array" do
|
52
|
-
@c.keys("*") do |resp|
|
53
|
-
resp.should == ["a","b","c"]
|
54
|
-
done
|
55
|
-
end
|
56
|
-
@c.receive_data "$5\r\na b c\r\n"
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# Inline response
|
61
|
-
should "parse an inline response" do
|
62
|
-
@c.call_command(["PING"]) do |resp|
|
63
|
-
resp.should == "OK"
|
64
|
-
done
|
65
|
-
end
|
66
|
-
@c.receive_data "+OK\r\n"
|
67
|
-
end
|
68
|
-
|
69
|
-
should "parse an inline integer response" do
|
70
|
-
@c.call_command(["integer"]) do |resp|
|
71
|
-
resp.should == 0
|
72
|
-
done
|
73
|
-
end
|
74
|
-
@c.receive_data ":0\r\n"
|
75
|
-
end
|
76
|
-
|
77
|
-
should "call processor if any" do
|
78
|
-
@c.call_command(["EXISTS"]) do |resp|
|
79
|
-
resp.should == false
|
80
|
-
done
|
81
|
-
end
|
82
|
-
@c.receive_data ":0\r\n"
|
83
|
-
end
|
84
|
-
|
85
|
-
should "parse an inline error response" do
|
86
|
-
@c.call_command(["blarg"]) do |resp|
|
87
|
-
resp.should == nil
|
88
|
-
done
|
89
|
-
end
|
90
|
-
@c.receive_data "-FAIL\r\n"
|
91
|
-
end
|
92
|
-
|
93
|
-
should "trigger a given error callback (specified with on_error) for inline error response instead of raising an error" do
|
94
|
-
lambda do
|
95
|
-
@c.call_command(["blarg"])
|
96
|
-
@c.on_error {|code| code.should == "FAIL"; done }
|
97
|
-
@c.receive_data "-FAIL\r\n"
|
98
|
-
end.should.not.raise(EM::P::Redis::RedisError)
|
99
|
-
end
|
100
|
-
|
101
|
-
should "trigger a given error callback for inline error response instead of raising an error" do
|
102
|
-
lambda do
|
103
|
-
@c.call_command(["blarg"])
|
104
|
-
@c.errback { |code| code.should == "FAIL"; done }
|
105
|
-
@c.receive_data "-FAIL\r\n"
|
106
|
-
end.should.not.raise(EM::P::Redis::RedisError)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Bulk response
|
110
|
-
should "parse a bulk response" do
|
111
|
-
@c.call_command(["GET", "foo"]) do |resp|
|
112
|
-
resp.should == "bar"
|
113
|
-
done
|
114
|
-
end
|
115
|
-
@c.receive_data "$3\r\n"
|
116
|
-
@c.receive_data "bar\r\n"
|
117
|
-
end
|
118
|
-
|
119
|
-
should "distinguish nil in a bulk response" do
|
120
|
-
@c.call_command(["GET", "bar"]) do |resp|
|
121
|
-
resp.should == nil
|
122
|
-
done
|
123
|
-
end
|
124
|
-
@c.receive_data "$-1\r\n"
|
125
|
-
end
|
126
|
-
|
127
|
-
# Multi-bulk response
|
128
|
-
should "parse a multi-bulk response" do
|
129
|
-
@c.call_command(["RANGE", 0, 10]) do |resp|
|
130
|
-
resp.should == ["a", "b", "foo"]
|
131
|
-
done
|
132
|
-
end
|
133
|
-
@c.receive_data "*3\r\n"
|
134
|
-
@c.receive_data "$1\r\na\r\n"
|
135
|
-
@c.receive_data "$1\r\nb\r\n"
|
136
|
-
@c.receive_data "$3\r\nfoo\r\n"
|
137
|
-
end
|
138
|
-
|
139
|
-
should "distinguish nil in a multi-bulk response" do
|
140
|
-
@c.call_command(["RANGE", 0, 10]) do |resp|
|
141
|
-
resp.should == ["a", nil, "foo"]
|
142
|
-
done
|
143
|
-
end
|
144
|
-
@c.receive_data "*3\r\n"
|
145
|
-
@c.receive_data "$1\r\na\r\n"
|
146
|
-
@c.receive_data "$-1\r\n"
|
147
|
-
@c.receive_data "$3\r\nfoo\r\n"
|
148
|
-
end
|
149
|
-
end
|
data/spec/test_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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 maybe_lock
|
19
|
-
yield
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
super
|
24
|
-
connection_completed
|
25
|
-
end
|
26
|
-
end
|