em-redislite 0.2.1 → 0.2.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/CHANGELOG +4 -0
- data/lib/em-synchrony/em-redislite.rb +0 -9
- data/lib/em/redis.rb +18 -7
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -7,15 +7,6 @@ module EM
|
|
7
7
|
def command name, *args
|
8
8
|
EM::Synchrony.sync send_command(name, *args)
|
9
9
|
end
|
10
|
-
|
11
|
-
def send_command name, *args
|
12
|
-
defer = DefaultDeferrable.new
|
13
|
-
@pool << defer
|
14
|
-
send_data "*#{args.length + 1}\r\n" +
|
15
|
-
"$#{name.length}\r\n#{name}\r\n" +
|
16
|
-
args.map(&:to_s).inject('') {|a,v| a + "$#{v.bytesize}\r\n#{v}\r\n"}
|
17
|
-
defer
|
18
|
-
end
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
data/lib/em/redis.rb
CHANGED
@@ -3,16 +3,18 @@ require 'eventmachine'
|
|
3
3
|
module EM
|
4
4
|
module Redis
|
5
5
|
|
6
|
-
VERSION = '0.2.
|
6
|
+
VERSION = '0.2.2'
|
7
7
|
DEFAULTS = { host: '127.0.0.1', port: 6379 }
|
8
8
|
|
9
|
-
class Error
|
9
|
+
class Error < StandardError; end
|
10
|
+
class DataError < Error; end
|
11
|
+
class ConnectionError < Error; end
|
10
12
|
|
11
13
|
def self.connect options = {}
|
12
14
|
options = DEFAULTS.merge(options)
|
13
15
|
begin
|
14
16
|
EM.connect options[:host], options[:port], Client, { host: options[:host], port: options[:port] }
|
15
|
-
rescue ConnectionError => e
|
17
|
+
rescue EM::ConnectionError => e
|
16
18
|
client = Client.new(nil)
|
17
19
|
client.fail(Error.new(e.message))
|
18
20
|
client
|
@@ -22,6 +24,8 @@ module EM
|
|
22
24
|
class Client < Connection
|
23
25
|
include Deferrable
|
24
26
|
|
27
|
+
DB_ERROR = 'lost redis connection'
|
28
|
+
|
25
29
|
def initialize options = {}
|
26
30
|
@options = options
|
27
31
|
end
|
@@ -38,8 +42,10 @@ module EM
|
|
38
42
|
signature ? super : true
|
39
43
|
end
|
40
44
|
|
41
|
-
def
|
45
|
+
def send_command name, *args
|
42
46
|
defer = DefaultDeferrable.new
|
47
|
+
return defer.tap {defer.fail(ConnectionError.new(DB_ERROR))} if error?
|
48
|
+
|
43
49
|
@pool << defer
|
44
50
|
send_data "*#{args.length + 1}\r\n" +
|
45
51
|
"$#{name.length}\r\n#{name}\r\n" +
|
@@ -47,6 +53,8 @@ module EM
|
|
47
53
|
defer
|
48
54
|
end
|
49
55
|
|
56
|
+
alias :command :send_command
|
57
|
+
|
50
58
|
def on_error msg, dns_error = false
|
51
59
|
unbind(msg)
|
52
60
|
end
|
@@ -59,8 +67,11 @@ module EM
|
|
59
67
|
EM.reconnect @options[:host], @options[:port], self
|
60
68
|
end
|
61
69
|
|
62
|
-
def unbind msg =
|
63
|
-
|
70
|
+
def unbind msg = DB_ERROR
|
71
|
+
close_connection
|
72
|
+
error = ConnectionError.new(msg)
|
73
|
+
@signature = nil
|
74
|
+
|
64
75
|
@pool.each {|r| r.fail(error) }
|
65
76
|
@pool = []
|
66
77
|
fail error
|
@@ -99,7 +110,7 @@ module EM
|
|
99
110
|
when ':' then @pool.shift.succeed(data[1..-1])
|
100
111
|
when '$' then @want_bytes = data[1..-1].to_i
|
101
112
|
when '*' then @want_lines = data[1..-1].to_i
|
102
|
-
else fail
|
113
|
+
else @pool.shift.fail DataError.new("Unknown data format: #{data}")
|
103
114
|
end
|
104
115
|
|
105
116
|
process_bytes(nil) if @want_bytes < 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-redislite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|