em-redis-unified 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1ea48665c31050fa49d2da3d09a4bdbedbbd4f3
4
- data.tar.gz: 7d25caee80d846063cc0c15cd1178c62fff1cdd9
3
+ metadata.gz: 54913b566f2a340684bd9a9406cec5ede44598cb
4
+ data.tar.gz: 04fd587693115490063b7dc5940a1574b097d840
5
5
  SHA512:
6
- metadata.gz: ba8dddac2c415bfb793002d1506e3f47c32b4117114d872f7466d4205c043d1c715ec81123d65c0552de4806eafa370a51afd9a7ff5cde1d6a2c29c9dd6adc0d
7
- data.tar.gz: ab139e9d3be94a9f9272a85b0e9c1c69087013f831a0d262a8495fee050be6055f283df30cb6bcc9eca0dd0f1ff833276f25a4d5da5af69d4f89ba5ed3cc931f
6
+ metadata.gz: a19fa4b7fba1819cb23599f8a1ae1c68822b5541fd0c356100a4c7f93cb29c2a5cb6fc6efe1d46f85d6d92ce338d2180c166bc1eb497b5cdc3e58edf15a73796
7
+ data.tar.gz: c33a49fb6177bb3bef4a79388ae8e36311501694d5cebed1f9d5f1bbece87f37d1bba2df42333705a18da80f381f54caf51bfa6efdda91a7cd9c82076d48fc61
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  .DS_Store
2
2
  pkg
3
+ *.lock
4
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Rakefile CHANGED
@@ -1,35 +1,6 @@
1
- # Look in the tasks/setup.rb file for the various options that can be
2
- # configured in this Rakefile. The .rake files in the tasks directory
3
- # are where the options are used.
1
+ require "bundler/gem_tasks"
4
2
 
5
- begin
6
- require 'bones'
7
- rescue LoadError
8
- abort '### Please install the "bones" gem ###'
9
- end
10
-
11
- ensure_in_path 'lib'
12
- require 'em-redis'
13
-
14
- task :default => ['redis:test']
15
-
16
- Bones {
17
- name 'em-redis-unified'
18
- authors ['Jonathan Broad', 'Eugene Pimenov', 'Sean Porter']
19
- email 'portertech@gmail.com'
20
- url 'http://github.com/portertech/em-redis'
21
- summary 'An eventmachine-based implementation of the Redis protocol'
22
- description summary
23
- version EMRedis::VERSION
24
-
25
- readme_file 'README.rdoc'
26
- ignore_file '.gitignore'
27
-
28
- depend_on 'eventmachine', '>=0.12.10'
29
-
30
- depend_on "bacon", :development => true
31
- depend_on "em-spec", :development => true
32
- }
3
+ task :default => ["redis:test"]
33
4
 
34
5
  namespace :redis do
35
6
  desc "Test em-redis against a live Redis"
@@ -37,5 +8,3 @@ namespace :redis do
37
8
  sh "bacon spec/live_redis_protocol_spec.rb spec/redis_commands_spec.rb spec/redis_protocol_spec.rb"
38
9
  end
39
10
  end
40
-
41
- # EOF
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+ require "em-redis/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "em-redis-unified"
7
+ spec.version = EMRedis::VERSION
8
+ spec.authors = ["Jonathan Broad", "Eugene Pimenov", "Sean Porter"]
9
+ spec.email = ["portertech@gmail.com"]
10
+ spec.summary = "An eventmachine-based implementation of the Redis protocol"
11
+ spec.description = "An eventmachine-based implementation of the Redis protocol"
12
+ spec.homepage = "https://github.com/portertech/em-redis"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency("eventmachine", ">= 0.12.10")
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "em-spec"
26
+ spec.add_development_dependency "bacon"
27
+ end
@@ -0,0 +1 @@
1
+ require "em-redis"
data/lib/em-redis.rb CHANGED
@@ -1,8 +1,6 @@
1
+ require File.join(File.dirname(__FILE__), 'em-redis/version')
1
2
 
2
3
  module EMRedis
3
-
4
- # :stopdoc:
5
- VERSION = '0.6.0'
6
4
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
5
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
6
  # :startdoc:
@@ -7,11 +7,13 @@ module EventMachine
7
7
  module Redis
8
8
  include EM::Deferrable
9
9
 
10
+ attr_accessor :auto_reconnect, :reconnect_on_error
11
+
10
12
  ##
11
13
  # constants
12
14
  #########################
13
15
 
14
- OK = "OK".freeze
16
+ OK = "OK".freeze
15
17
  MINUS = "-".freeze
16
18
  PLUS = "+".freeze
17
19
  COLON = ":".freeze
@@ -191,6 +193,26 @@ module EventMachine
191
193
  end
192
194
  end
193
195
 
196
+ def subscribe(channel, proc=nil, &blk)
197
+ @subscribe_callbacks ||= Hash.new([])
198
+ @subscribe_callbacks[channel] += [(proc || blk)]
199
+ call_command(['subscribe', channel], &blk)
200
+ end
201
+
202
+ def unsubscribe(channel=nil, &blk)
203
+ @subscribe_callbacks ||= Hash.new([])
204
+ argv = ["unsubscribe"]
205
+ if channel
206
+ @subscribe_callbacks[channel] = [blk]
207
+ argv << channel
208
+ else
209
+ @subscribe_callbacks.each_key do |key|
210
+ @subscribe_callbacks[key] = [blk]
211
+ end
212
+ end
213
+ callback { send_command(argv) }
214
+ end
215
+
194
216
  # Ruby defines a now deprecated type method so we need to override it here
195
217
  # since it will never hit method_missing
196
218
  def type(key, &blk)
@@ -356,7 +378,7 @@ module EventMachine
356
378
 
357
379
  def auth_and_select_db
358
380
  # auth and select go to the front of the line
359
- callbacks = @callbacks
381
+ callbacks = @callbacks || []
360
382
  @callbacks = []
361
383
  call_command(["auth", @password]) if @password
362
384
  call_command(["select", @db]) unless @db == 0
@@ -366,12 +388,12 @@ module EventMachine
366
388
 
367
389
  def connection_completed
368
390
  @logger.debug { "Connected to #{@host}:#{@port}" } if @logger
369
- @reconnect_callbacks[:after].call if @reconnecting
370
391
  @redis_callbacks = []
371
392
  @multibulk_n = false
372
- @reconnecting = false
373
393
  @connected = true
374
394
  auth_and_select_db
395
+ @reconnect_callbacks[:after].call if @reconnecting
396
+ @reconnecting = false
375
397
  succeed
376
398
  end
377
399
 
@@ -451,6 +473,15 @@ module EventMachine
451
473
  end
452
474
  end
453
475
 
476
+ if @subscribe_callbacks && value.is_a?(Array)
477
+ if %w[message unsubscribe].include?(value[0])
478
+ @subscribe_callbacks[value[1]].each do |blk|
479
+ blk.call(*value) if blk
480
+ end
481
+ return
482
+ end
483
+ end
484
+
454
485
  callback = @redis_callbacks.shift
455
486
  if callback.kind_of?(Array) && callback.length == 2
456
487
  processor, blk = callback
@@ -478,6 +509,15 @@ module EventMachine
478
509
  @connected || false
479
510
  end
480
511
 
512
+ def reconnect!
513
+ @reconnect_callbacks[:before].call unless @reconnecting
514
+ @reconnecting = true
515
+ EM.add_timer(1) do
516
+ @logger.debug { "Reconnecting to #{@host}:#{@port}" } if @logger
517
+ reconnect(@host, @port)
518
+ end
519
+ end
520
+
481
521
  def close
482
522
  @closing = true
483
523
  close_connection_after_writing
@@ -488,12 +528,7 @@ module EventMachine
488
528
  if @closing
489
529
  @reconnecting = false
490
530
  elsif ((@connected || @reconnecting) && @auto_reconnect) || @reconnect_on_error
491
- @reconnect_callbacks[:before].call unless @reconnecting
492
- @reconnecting = true
493
- EM.add_timer(1) do
494
- @logger.debug { "Reconnecting to #{@host}:#{@port}" } if @logger
495
- reconnect @host, @port
496
- end
531
+ reconnect!
497
532
  elsif @connected
498
533
  error ConnectionError, 'connection closed'
499
534
  else
@@ -0,0 +1,4 @@
1
+ module EMRedis
2
+ # :stopdoc:
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
2
+
3
+ EM.describe EM::Protocols::Redis, "connected to an empty db" do
4
+
5
+ before do
6
+ @s = EM::Protocols::Redis.connect(:db => 14)
7
+ @p = EM::Protocols::Redis.connect(:db => 14)
8
+ end
9
+
10
+ should "be able to publish a message to a channel" do
11
+ @p.flushdb do
12
+ @p.publish("foo", "test") do |r|
13
+ r.should == 0
14
+ done
15
+ end
16
+ end
17
+ end
18
+
19
+ should "be able to subscribe to a channel and then unsubscribe" do
20
+ @s.flushdb do
21
+ @s.subscribe("foo", Proc.new {}) do |type, channel, subscribers|
22
+ type.should == "subscribe"
23
+ channel.should == "foo"
24
+ subscribers.should == 1
25
+ @s.unsubscribe do
26
+ done
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ should "be able to subscribe to a channel and publish a message to it" do
33
+ @s.flushdb do
34
+ callback = Proc.new do |type, channel, message|
35
+ type.should == "message"
36
+ channel.should == "foo"
37
+ message.should == "test"
38
+ done
39
+ end
40
+ @s.subscribe("foo", callback) do |type, channel, subscribers|
41
+ type.should == "subscribe"
42
+ channel.should == "foo"
43
+ subscribers.should == 1
44
+ @p.publish("foo", "test") do |r|
45
+ r.should == 1
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-redis-unified
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Broad
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-13 00:00:00.000000000 Z
13
+ date: 2015-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -27,7 +27,35 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.12.10
29
29
  - !ruby/object:Gem::Dependency
30
- name: bacon
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.6'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
31
59
  requirement: !ruby/object:Gem::Requirement
32
60
  requirements:
33
61
  - - ">="
@@ -55,44 +83,47 @@ dependencies:
55
83
  - !ruby/object:Gem::Version
56
84
  version: '0'
57
85
  - !ruby/object:Gem::Dependency
58
- name: bones
86
+ name: bacon
59
87
  requirement: !ruby/object:Gem::Requirement
60
88
  requirements:
61
89
  - - ">="
62
90
  - !ruby/object:Gem::Version
63
- version: 3.8.1
91
+ version: '0'
64
92
  type: :development
65
93
  prerelease: false
66
94
  version_requirements: !ruby/object:Gem::Requirement
67
95
  requirements:
68
96
  - - ">="
69
97
  - !ruby/object:Gem::Version
70
- version: 3.8.1
98
+ version: '0'
71
99
  description: An eventmachine-based implementation of the Redis protocol
72
- email: portertech@gmail.com
100
+ email:
101
+ - portertech@gmail.com
73
102
  executables: []
74
103
  extensions: []
75
- extra_rdoc_files:
76
- - History.txt
77
- - README.rdoc
104
+ extra_rdoc_files: []
78
105
  files:
79
106
  - ".gitignore"
107
+ - Gemfile
80
108
  - History.txt
81
109
  - README.rdoc
82
110
  - Rakefile
111
+ - em-redis-unified.gemspec
112
+ - lib/em-redis-unified.rb
83
113
  - lib/em-redis.rb
84
114
  - lib/em-redis/redis_protocol.rb
115
+ - lib/em-redis/version.rb
85
116
  - spec/live_redis_protocol_spec.rb
117
+ - spec/live_redis_pubsub_spec.rb
86
118
  - spec/redis_commands_spec.rb
87
119
  - spec/redis_protocol_spec.rb
88
120
  - spec/test_helper.rb
89
- homepage: http://github.com/portertech/em-redis
90
- licenses: []
121
+ homepage: https://github.com/portertech/em-redis
122
+ licenses:
123
+ - MIT
91
124
  metadata: {}
92
125
  post_install_message:
93
- rdoc_options:
94
- - "--main"
95
- - README.rdoc
126
+ rdoc_options: []
96
127
  require_paths:
97
128
  - lib
98
129
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -106,9 +137,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
137
  - !ruby/object:Gem::Version
107
138
  version: '0'
108
139
  requirements: []
109
- rubyforge_project: em-redis-unified
140
+ rubyforge_project:
110
141
  rubygems_version: 2.2.2
111
142
  signing_key:
112
143
  specification_version: 4
113
144
  summary: An eventmachine-based implementation of the Redis protocol
114
- test_files: []
145
+ test_files:
146
+ - spec/live_redis_protocol_spec.rb
147
+ - spec/live_redis_pubsub_spec.rb
148
+ - spec/redis_commands_spec.rb
149
+ - spec/redis_protocol_spec.rb
150
+ - spec/test_helper.rb