em-hiredis 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile +4 -2
- data/README.md +28 -5
- data/Rakefile +9 -0
- data/em-hiredis.gemspec +2 -2
- data/lib/em-hiredis.rb +22 -10
- data/lib/em-hiredis/client.rb +68 -30
- data/lib/em-hiredis/connection.rb +4 -4
- data/lib/em-hiredis/event_emitter.rb +1 -1
- data/lib/em-hiredis/version.rb +2 -2
- data/spec/connection_spec.rb +56 -0
- data/spec/live_redis_protocol_spec.rb +512 -0
- data/spec/redis_commands_spec.rb +910 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/connection_helper.rb +9 -0
- data/spec/support/redis_mock.rb +65 -0
- data/spec/url_param_spec.rb +43 -0
- metadata +20 -6
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
|
+
require 'em-hiredis'
|
3
|
+
require 'rspec'
|
4
|
+
require 'em-spec/rspec'
|
5
|
+
|
6
|
+
require 'support/connection_helper'
|
7
|
+
require 'support/redis_mock'
|
8
|
+
require 'stringio'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include ConnectionHelper
|
12
|
+
config.include EventMachine::SpecHelper
|
13
|
+
config.include RedisMock::Helper
|
14
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# nabbed from redis-rb, thanks!
|
2
|
+
require "socket"
|
3
|
+
|
4
|
+
module RedisMock
|
5
|
+
def self.start(port = 6380)
|
6
|
+
server = TCPServer.new("127.0.0.1", port)
|
7
|
+
|
8
|
+
loop do
|
9
|
+
session = server.accept
|
10
|
+
|
11
|
+
while line = session.gets
|
12
|
+
parts = Array.new(line[1..-3].to_i) do
|
13
|
+
bytes = session.gets[1..-3].to_i
|
14
|
+
argument = session.read(bytes)
|
15
|
+
session.read(2) # Discard \r\n
|
16
|
+
argument
|
17
|
+
end
|
18
|
+
|
19
|
+
response = yield(*parts)
|
20
|
+
|
21
|
+
if response.nil?
|
22
|
+
session.shutdown(Socket::SHUT_RDWR)
|
23
|
+
break
|
24
|
+
else
|
25
|
+
session.write(response)
|
26
|
+
session.write("\r\n")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Helper
|
33
|
+
# Forks the current process and starts a new mock Redis server on
|
34
|
+
# port 6380.
|
35
|
+
#
|
36
|
+
# The server will reply with a `+OK` to all commands, but you can
|
37
|
+
# customize it by providing a hash. For example:
|
38
|
+
#
|
39
|
+
# redis_mock(:ping => lambda { "+PONG" }) do
|
40
|
+
# assert_equal "PONG", Redis.new(:port => 6380).ping
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
def redis_mock(replies = {})
|
44
|
+
begin
|
45
|
+
pid = fork do
|
46
|
+
trap("TERM") { exit }
|
47
|
+
|
48
|
+
RedisMock.start do |command, *args|
|
49
|
+
(replies[command.to_sym] || lambda { |*_| "+OK" }).call(*args)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
sleep 1 # Give time for the socket to start listening.
|
54
|
+
|
55
|
+
yield
|
56
|
+
|
57
|
+
ensure
|
58
|
+
if pid
|
59
|
+
Process.kill("TERM", pid)
|
60
|
+
Process.wait(pid)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# adapted from redis-rb
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe EventMachine::Hiredis, "URL parsing" do
|
5
|
+
it "defaults URL defaults to 127.0.0.1:6379" do
|
6
|
+
redis = EventMachine::Hiredis.setup
|
7
|
+
|
8
|
+
redis.host.should == "127.0.0.1"
|
9
|
+
redis.port.should == 6379
|
10
|
+
redis.db.should == "0"
|
11
|
+
redis.password.should == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "allows to pass in a URL" do
|
15
|
+
redis = EventMachine::Hiredis.setup "redis://:secr3t@foo.com:999/2"
|
16
|
+
|
17
|
+
redis.host.should == "foo.com"
|
18
|
+
redis.port.should == 999
|
19
|
+
redis.db.should == "2"
|
20
|
+
redis.password.should == "secr3t"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not modify the passed options" do
|
24
|
+
options = "redis://:secr3t@foo.com:999/2"
|
25
|
+
|
26
|
+
redis = EventMachine::Hiredis.setup(options)
|
27
|
+
|
28
|
+
options.should == "redis://:secr3t@foo.com:999/2"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "uses REDIS_URL over default if available" do
|
32
|
+
ENV["REDIS_URL"] = "redis://:secr3t@foo.com:999/2"
|
33
|
+
|
34
|
+
redis = EventMachine::Hiredis.setup
|
35
|
+
|
36
|
+
redis.host.should == "foo.com"
|
37
|
+
redis.port.should == 999
|
38
|
+
redis.db.should == "2"
|
39
|
+
redis.password.should == "secr3t"
|
40
|
+
|
41
|
+
ENV.delete("REDIS_URL")
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: em-hiredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Martyn Loughran
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-04 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.
|
24
|
+
version: 0.3.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
description: Eventmachine redis client using hiredis native parser
|
@@ -35,6 +35,7 @@ extra_rdoc_files: []
|
|
35
35
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
|
+
- .rspec
|
38
39
|
- Gemfile
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|
@@ -44,6 +45,13 @@ files:
|
|
44
45
|
- lib/em-hiredis/connection.rb
|
45
46
|
- lib/em-hiredis/event_emitter.rb
|
46
47
|
- lib/em-hiredis/version.rb
|
48
|
+
- spec/connection_spec.rb
|
49
|
+
- spec/live_redis_protocol_spec.rb
|
50
|
+
- spec/redis_commands_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/support/connection_helper.rb
|
53
|
+
- spec/support/redis_mock.rb
|
54
|
+
- spec/url_param_spec.rb
|
47
55
|
has_rdoc: true
|
48
56
|
homepage: http://github.com/mloughran/em-hiredis
|
49
57
|
licenses: []
|
@@ -68,9 +76,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
76
|
requirements: []
|
69
77
|
|
70
78
|
rubyforge_project: em-hiredis
|
71
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.6.2
|
72
80
|
signing_key:
|
73
81
|
specification_version: 3
|
74
82
|
summary: Eventmachine redis client
|
75
|
-
test_files:
|
76
|
-
|
83
|
+
test_files:
|
84
|
+
- spec/connection_spec.rb
|
85
|
+
- spec/live_redis_protocol_spec.rb
|
86
|
+
- spec/redis_commands_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/support/connection_helper.rb
|
89
|
+
- spec/support/redis_mock.rb
|
90
|
+
- spec/url_param_spec.rb
|