eventmachine-redis 0.1.2 → 0.1.3

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.
@@ -2,6 +2,16 @@
2
2
 
3
3
  An [EventMachine](http://github.com/eventmachine/eventmachine/) based Redis client.
4
4
 
5
+ ## Example
6
+
7
+ EM.run do
8
+ Redis = EM::Protocols::Redis.connect
9
+ Redis.push('queue', 'Hello!') do
10
+ shift = Redis.shift('queue') { |value| puts value }
11
+ shift.callback { EM.stop }
12
+ end
13
+ end
14
+
5
15
  ## Warning
6
16
 
7
17
  This was written as a learning exercise and is currently very incomplete.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eventmachine-redis}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tristan Dunn"]
12
- s.date = %q{2010-03-29}
12
+ s.date = %q{2010-05-08}
13
13
  s.description = %q{An EventMachine based Redis client.}
14
14
  s.email = %q{hello@tristandunn.com}
15
15
  s.extra_rdoc_files = [
@@ -9,7 +9,7 @@ module EventMachine::Protocols::Redis
9
9
  TYPE_INTEGER = ':'.freeze
10
10
  TYPE_MULTIPLE = '*'.freeze
11
11
 
12
- MULTILINE_COMMANDS = %w(PUBLISH).freeze
12
+ MULTILINE_COMMANDS = %w(PUBLISH RPUSH).freeze
13
13
 
14
14
  def self.connect(host = 'localhost', port = 6379)
15
15
  EM.connect(host, port, self)
@@ -45,6 +45,10 @@ module EventMachine::Protocols::Redis
45
45
  command('PUBLISH', channel, message, &block)
46
46
  end
47
47
 
48
+ def push(key, item, &block)
49
+ command('RPUSH', key, item, &block)
50
+ end
51
+
48
52
  def shift(key, options = {}, &block)
49
53
  if options[:timeout]
50
54
  command('BLPOP', key, options[:timeout], &block)
@@ -55,9 +59,16 @@ module EventMachine::Protocols::Redis
55
59
 
56
60
  protected
57
61
 
58
- def command(*arguments, &block)
59
- @handlers << block
62
+ def add_handler(&block)
63
+ deferrable = EM::DefaultDeferrable.new
64
+ deferrable.callback(&block) if block_given?
65
+
66
+ @handlers.push(deferrable)
60
67
 
68
+ deferrable
69
+ end
70
+
71
+ def command(*arguments, &block)
61
72
  callback do
62
73
  command = arguments.shift
63
74
  multiline = MULTILINE_COMMANDS.include?(command)
@@ -69,11 +80,13 @@ module EventMachine::Protocols::Redis
69
80
 
70
81
  send_data(command)
71
82
  end
83
+
84
+ add_handler(&block)
72
85
  end
73
86
 
74
87
  def handler(*arguments)
75
88
  handler = @handlers.shift
76
- handler.call(*arguments) if handler
89
+ handler.succeed(*arguments) if handler
77
90
  end
78
91
 
79
92
  def process_response(response)
@@ -25,7 +25,7 @@ describe EventMachine::Protocols::Redis do
25
25
  end
26
26
 
27
27
  it 'should define multiline commands constant' do
28
- Redis::MULTILINE_COMMANDS.should == %w(PUBLISH)
28
+ Redis::MULTILINE_COMMANDS.should == %w(PUBLISH RPUSH)
29
29
  end
30
30
 
31
31
  it 'should connect via EventMachine when calling Redis.connect' do
@@ -88,6 +88,12 @@ describe EventMachine::Protocols::Redis do
88
88
  @completed.should be_true
89
89
  end
90
90
 
91
+ describe '#command' do
92
+ it 'should return an EventMachine deferrable object' do
93
+ @instance.shift('key').should be_a(EventMachine::Deferrable)
94
+ end
95
+ end
96
+
91
97
  describe '#publish' do
92
98
  it 'should generate PUBLISH command' do
93
99
  @instance.publish('channel', 'message')
@@ -95,6 +101,13 @@ describe EventMachine::Protocols::Redis do
95
101
  end
96
102
  end
97
103
 
104
+ describe '#push' do
105
+ it 'should generate RPUSH command' do
106
+ @instance.push('key', 'item')
107
+ @instance.sent_data.should == "RPUSH key 4\r\nitem\r\n"
108
+ end
109
+ end
110
+
98
111
  describe '#shift' do
99
112
  it 'should generate LPOP command' do
100
113
  @instance.shift('key')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tristan Dunn
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-29 00:00:00 -04:00
17
+ date: 2010-05-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20