cs-em-hiredis 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENCE +19 -0
- data/README.md +85 -0
- data/Rakefile +11 -0
- data/cs-em-hiredis.gemspec +25 -0
- data/examples/pubsub.rb +52 -0
- data/lib/em-hiredis.rb +49 -0
- data/lib/em-hiredis/base_client.rb +199 -0
- data/lib/em-hiredis/client.rb +51 -0
- data/lib/em-hiredis/connection.rb +70 -0
- data/lib/em-hiredis/event_emitter.rb +29 -0
- data/lib/em-hiredis/lock.rb +89 -0
- data/lib/em-hiredis/pubsub_client.rb +187 -0
- data/lib/em-hiredis/version.rb +5 -0
- data/spec/base_client_spec.rb +115 -0
- data/spec/connection_spec.rb +56 -0
- data/spec/live_redis_protocol_spec.rb +527 -0
- data/spec/pubsub_spec.rb +314 -0
- data/spec/redis_commands_spec.rb +910 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/connection_helper.rb +11 -0
- data/spec/support/redis_mock.rb +65 -0
- data/spec/url_param_spec.rb +43 -0
- metadata +125 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
15
|
+
|
16
|
+
# This speeds the tests up a bit
|
17
|
+
EM::Hiredis.reconnect_timeout = 0.01
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ConnectionHelper
|
2
|
+
# Use db 9 for tests to avoid flushing the main db
|
3
|
+
# It would be nice if there was a standard db number for testing...
|
4
|
+
def connect(timeout = 1, url = "redis://localhost:6379/9", &blk)
|
5
|
+
em(timeout) do
|
6
|
+
redis = EventMachine::Hiredis.connect(url)
|
7
|
+
redis.flushdb
|
8
|
+
blk.call(redis)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
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
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cs-em-hiredis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martyn Loughran
|
9
|
+
- Yuri Niyazov
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-05-01 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hiredis
|
17
|
+
requirement: &70267995278560 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70267995278560
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: em-spec
|
28
|
+
requirement: &70267995279500 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.5
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70267995279500
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70267995278720 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.6.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70267995278720
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &70267995278140 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70267995278140
|
59
|
+
description: Eventmachine redis client using hiredis native parser
|
60
|
+
email:
|
61
|
+
- me@mloughran.com
|
62
|
+
- yuri.niyazov@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- .gitignore
|
68
|
+
- .rspec
|
69
|
+
- Gemfile
|
70
|
+
- LICENCE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- cs-em-hiredis.gemspec
|
74
|
+
- examples/pubsub.rb
|
75
|
+
- lib/em-hiredis.rb
|
76
|
+
- lib/em-hiredis/base_client.rb
|
77
|
+
- lib/em-hiredis/client.rb
|
78
|
+
- lib/em-hiredis/connection.rb
|
79
|
+
- lib/em-hiredis/event_emitter.rb
|
80
|
+
- lib/em-hiredis/lock.rb
|
81
|
+
- lib/em-hiredis/pubsub_client.rb
|
82
|
+
- lib/em-hiredis/version.rb
|
83
|
+
- spec/base_client_spec.rb
|
84
|
+
- spec/connection_spec.rb
|
85
|
+
- spec/live_redis_protocol_spec.rb
|
86
|
+
- spec/pubsub_spec.rb
|
87
|
+
- spec/redis_commands_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/support/connection_helper.rb
|
90
|
+
- spec/support/redis_mock.rb
|
91
|
+
- spec/url_param_spec.rb
|
92
|
+
homepage: http://github.com/yn/em-hiredis
|
93
|
+
licenses: []
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.10
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Eventmachine redis client
|
116
|
+
test_files:
|
117
|
+
- spec/base_client_spec.rb
|
118
|
+
- spec/connection_spec.rb
|
119
|
+
- spec/live_redis_protocol_spec.rb
|
120
|
+
- spec/pubsub_spec.rb
|
121
|
+
- spec/redis_commands_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/support/connection_helper.rb
|
124
|
+
- spec/support/redis_mock.rb
|
125
|
+
- spec/url_param_spec.rb
|