gio-redis 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gio-redis.gemspec +1 -0
- data/lib/gio/redis/version.rb +1 -1
- data/lib/gio/redis.rb +39 -10
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d75e20471a85809648d47357c950211657aec17a
|
4
|
+
data.tar.gz: ee2f7eaed1760cdacca425ec109e29dde1baa3a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ceda2a4a3566d4a1e1e0bcc891ed1a8db2538108a9b83017df6e879437c7ac2eb3f187f6c05c774baa4207414eaee8a0b0c1545e7fc8dbaf8f51c4e822429ac
|
7
|
+
data.tar.gz: 5197119e9a0d53e6307f6aee00e7dba23c5b1f86534f795608638f8fd14ae052e77a3ce946d5fae840230a2276be482bcd87e6c0393c486475356164e4ac97d7
|
data/gio-redis.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'hiredis'
|
22
22
|
spec.add_dependency 'gio2'
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency 'redis'
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "gtk2"
|
26
27
|
end
|
data/lib/gio/redis/version.rb
CHANGED
data/lib/gio/redis.rb
CHANGED
@@ -7,15 +7,24 @@ module Gio
|
|
7
7
|
# Your code goes here...
|
8
8
|
def initialize(host = '127.0.0.1', port = 6379, mainloop = nil)
|
9
9
|
|
10
|
-
@addr = Gio::InetSocketAddress.new(
|
11
|
-
@sock =
|
10
|
+
@addr = Gio::InetSocketAddress.new(inet_address_from_string(host), port)
|
11
|
+
@sock = Gio::Socket.new(:ipv4, :stream, :tcp)
|
12
12
|
|
13
13
|
@sock.connect(@addr)
|
14
14
|
@sock.set_blocking(false)
|
15
15
|
|
16
|
-
@
|
16
|
+
@redis_reader = Hiredis::Reader.new
|
17
|
+
|
18
|
+
if defined?(Gio::PollableInputStream)
|
19
|
+
@reader = Gio::UnixInputStream.new(@sock.fd, false)
|
20
|
+
@source = @reader.create_source(&method(:read_response))
|
21
|
+
@writer = Gio::UnixOutputStream.new(@sock.fd, false)
|
22
|
+
else
|
23
|
+
@source = @sock.create_source(GLib::IOCondition::IN, &method(:read_response))
|
24
|
+
@writer = @sock
|
25
|
+
@reader = @sock
|
26
|
+
end
|
17
27
|
|
18
|
-
@source = @sock.create_source(GLib::IOCondition::IN, &method(:read_response))
|
19
28
|
@source.attach
|
20
29
|
@pong = false
|
21
30
|
@callbacks = {}
|
@@ -41,6 +50,14 @@ module Gio
|
|
41
50
|
end
|
42
51
|
|
43
52
|
private
|
53
|
+
def inet_address_from_string(host)
|
54
|
+
if Gio::InetAddress.respond_to?(:new_from_string)
|
55
|
+
Gio::InetAddress.new_from_string(host)
|
56
|
+
else
|
57
|
+
Gio::InetAddress.new(host)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
44
61
|
def call_command(*args)
|
45
62
|
command = "*#{args.size}\r\n"
|
46
63
|
args.each { |a|
|
@@ -48,14 +65,18 @@ module Gio
|
|
48
65
|
command << a.to_s
|
49
66
|
command << "\r\n"
|
50
67
|
}
|
51
|
-
@
|
68
|
+
if @writer.respond_to?(:write_nonblocking)
|
69
|
+
@writer.write_nonblocking command
|
70
|
+
else
|
71
|
+
@writer.send command
|
72
|
+
end
|
52
73
|
end
|
53
74
|
|
54
75
|
def read_response(source=nil, condition=nil)
|
55
76
|
while data = read(4096)
|
56
|
-
@
|
77
|
+
@redis_reader.feed(data)
|
57
78
|
|
58
|
-
while response = @
|
79
|
+
while response = @redis_reader.gets
|
59
80
|
case response
|
60
81
|
when 'PONG'
|
61
82
|
@pong = true
|
@@ -77,9 +98,17 @@ module Gio
|
|
77
98
|
end
|
78
99
|
|
79
100
|
def read(n)
|
80
|
-
@
|
81
|
-
|
82
|
-
|
101
|
+
if @reader.respond_to?(:read_nonblocking)
|
102
|
+
begin @reader.read_nonblocking(n)
|
103
|
+
rescue Gio::IOError::WouldBlock => e
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
else
|
107
|
+
begin @reader.receive(n)
|
108
|
+
rescue Gio::IO::WouldBlockError => e
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
83
112
|
end
|
84
113
|
end
|
85
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gio-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- |
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiredis
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '1.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: redis
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: rake
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
132
|
version: '0'
|
119
133
|
requirements: []
|
120
134
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.2.2
|
122
136
|
signing_key:
|
123
137
|
specification_version: 4
|
124
138
|
summary: gio2 based redis pub/sub listener
|