redis-protocol 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/lib/redis-protocol.rb +2 -1
- data/lib/redis-protocol/static_request.rb +7 -4
- data/spec/redis-protocol/static_request_spec.rb +54 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/redis-protocol.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class RedisProtocol::StaticRequest
|
2
|
-
attr_reader :raw_data, :type
|
2
|
+
attr_reader :raw_data, :type, :components, :component_count
|
3
3
|
OP_DELIMITER = "\r\n"
|
4
4
|
|
5
5
|
def initialize(data)
|
@@ -10,7 +10,7 @@ class RedisProtocol::StaticRequest
|
|
10
10
|
def parse_request
|
11
11
|
@type = check_request_type
|
12
12
|
|
13
|
-
send @type
|
13
|
+
send @type
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.recognize(data)
|
@@ -29,6 +29,7 @@ class RedisProtocol::StaticRequest
|
|
29
29
|
data, payload = unpack_payload(payload)
|
30
30
|
components << data
|
31
31
|
end
|
32
|
+
@component_count = components.count
|
32
33
|
@components = components
|
33
34
|
end
|
34
35
|
|
@@ -47,8 +48,10 @@ class RedisProtocol::StaticRequest
|
|
47
48
|
next_token payload, field_length
|
48
49
|
end
|
49
50
|
|
50
|
-
def inline
|
51
|
-
|
51
|
+
def inline
|
52
|
+
@components = @raw_data.split
|
53
|
+
@component_count = @components.count
|
54
|
+
@components
|
52
55
|
end
|
53
56
|
|
54
57
|
def next_token(data, length = 0)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe RedisProtocol::StaticRequest do
|
4
|
+
it 'initialize with data' do
|
5
|
+
RedisProtocol::StaticRequest.new 'ping'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should get raw data as original' do
|
9
|
+
request = RedisProtocol::StaticRequest.new 'ping'
|
10
|
+
request.raw_data.should eql 'ping'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should parse inline command' do
|
14
|
+
request = RedisProtocol::StaticRequest.new 'ping'
|
15
|
+
request.components[0].should eql 'ping'
|
16
|
+
request.component_count.should be 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should parse inline command with parameter' do
|
20
|
+
request = RedisProtocol::StaticRequest.new 'keys *'
|
21
|
+
request.components[0].should eql 'keys'
|
22
|
+
request.component_count.should be 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should parse inline command with multi whitespaces' do
|
26
|
+
request = RedisProtocol::StaticRequest.new 'keys *'
|
27
|
+
request.components[0].should eql 'keys'
|
28
|
+
request.component_count.should be 2
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should parse standard command' do
|
32
|
+
request = RedisProtocol::StaticRequest.new "*1\r\n$4\r\nping"
|
33
|
+
request.components[0].should eql 'ping'
|
34
|
+
request.component_count.should be 1
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should parse standard command with parameter' do
|
38
|
+
request = RedisProtocol::StaticRequest.new "*2\r\n$4\r\nkeys\r\n$1\r\n*"
|
39
|
+
request.components[0].should eql 'keys'
|
40
|
+
request.component_count.should be 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should parse standard command with multiple parameters' do
|
44
|
+
request = RedisProtocol::StaticRequest.new "*3\r\n$3\r\nset\r\n$4\r\ntest\r\n$5\r\nhello"
|
45
|
+
request.components[0].should eql 'set'
|
46
|
+
request.component_count.should be 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should parse standard command containing delimiter' do
|
50
|
+
request = RedisProtocol::StaticRequest.new "*3\r\n$3\r\nset\r\n$4\r\ntest\r\n$12\r\nhello\r\nworld"
|
51
|
+
request.components[2].should eql "hello\r\nworld"
|
52
|
+
request.component_count.should be 3
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/redis-protocol/request.rb
|
130
130
|
- lib/redis-protocol/static_request.rb
|
131
131
|
- spec/redis-protocol/request_spec.rb
|
132
|
+
- spec/redis-protocol/static_request_spec.rb
|
132
133
|
- spec/redis-protocol_spec.rb
|
133
134
|
- spec/spec_helper.rb
|
134
135
|
homepage: http://github.com/astral1/redis-protocol
|
@@ -146,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
147
|
version: '0'
|
147
148
|
segments:
|
148
149
|
- 0
|
149
|
-
hash:
|
150
|
+
hash: 3700473079050196087
|
150
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
152
|
none: false
|
152
153
|
requirements:
|