superfeedr-em-redis 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ pkg
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Bones {
17
17
  name 'superfeedr-em-redis'
18
18
  authors ['Jonathan Broad', 'Eugene Pimenov', 'Stephan Maka']
19
19
  email 'stephan@spaceboyz.net'
20
- url 'http://github.com/libc/em-redis'
21
- summary 'An eventmachine-based implementation of the Redis protocol'
20
+ url 'http://github.com/astro/em-redis'
21
+ summary 'An eventmachine-based implementation of the Redis protocol (forked)'
22
22
  description summary
23
23
  version EMRedis::VERSION
24
24
 
@@ -44,7 +44,7 @@ module EventMachine
44
44
  "multi_get" => true
45
45
  }
46
46
 
47
- BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
47
+ BOOLEAN_PROCESSOR = lambda{|r| %w(1 OK).include? r.to_s }
48
48
 
49
49
  REPLY_PROCESSOR = {
50
50
  "exists" => BOOLEAN_PROCESSOR,
@@ -232,6 +232,32 @@ module EventMachine
232
232
  end
233
233
 
234
234
  def raw_call_command(argv, &blk)
235
+ argv[0] = argv[0].to_s unless argv[0].kind_of? String
236
+ send_command(argv)
237
+ @redis_callbacks << [REPLY_PROCESSOR[argv[0]], blk]
238
+ end
239
+
240
+ def call_commands(argvs, &blk)
241
+ callback { raw_call_commands(argvs, &blk) }
242
+ end
243
+
244
+ def raw_call_commands(argvs, &blk)
245
+ if argvs.empty? # Shortcut
246
+ blk.call []
247
+ return
248
+ end
249
+
250
+ argvs.each do |argv|
251
+ argv[0] = argv[0].to_s unless argv[0].kind_of? String
252
+ send_command argv
253
+ end
254
+ # FIXME: argvs may contain heterogenous commands, storing all
255
+ # REPLY_PROCESSORs may turn out expensive and has been omitted
256
+ # for now.
257
+ @redis_callbacks << [nil, argvs.length, blk]
258
+ end
259
+
260
+ def send_command(argv)
235
261
  argv = argv.dup
236
262
 
237
263
  if MULTI_BULK_COMMANDS[argv.flatten[0].to_s]
@@ -261,7 +287,6 @@ module EventMachine
261
287
  end
262
288
 
263
289
  @logger.debug { "*** sending: #{command}" } if @logger
264
- @redis_callbacks << [REPLY_PROCESSOR[argv[0]], blk]
265
290
  send_data command
266
291
  end
267
292
 
@@ -313,6 +338,7 @@ module EventMachine
313
338
  err.code = code
314
339
  raise err, "Redis server returned error code: #{code}"
315
340
  end
341
+ @values = []
316
342
 
317
343
  # These commands should be first
318
344
  auth_and_select_db
@@ -361,7 +387,7 @@ module EventMachine
361
387
  #e.g. -MISSING
362
388
  when MINUS
363
389
  # Missing, dispatch empty response
364
- dispatch_response('')
390
+ dispatch_response(nil)
365
391
  # e.g. +OK
366
392
  when PLUS
367
393
  dispatch_response(reply_args)
@@ -409,9 +435,22 @@ module EventMachine
409
435
  end
410
436
  end
411
437
 
412
- processor, blk = @redis_callbacks.shift
413
- value = processor.call(value) if processor
414
- blk.call(value) if blk
438
+ callback = @redis_callbacks.shift
439
+ if callback.length == 2
440
+ processor, blk = callback
441
+ value = processor.call(value) if processor
442
+ blk.call(value) if blk
443
+ else
444
+ processor, pipeline_count, blk = callback
445
+ value = processor.call(value) if processor
446
+ @values << value
447
+ if pipeline_count > 1
448
+ @redis_callbacks.unshift [processor, pipeline_count - 1, blk]
449
+ else
450
+ blk.call(@values) if blk
451
+ @values = []
452
+ end
453
+ end
415
454
  end
416
455
 
417
456
  def start_multibulk(multibulk_count)
data/lib/em-redis.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module EMRedis
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '0.2.3'
5
+ VERSION = '0.2.4'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -551,9 +551,8 @@ EM.describe EM::Protocols::Redis do
551
551
 
552
552
  # attempt to update a key that's not a zset
553
553
  @r["i_am_not_a_zet"] = "value"
554
- # should raise error
555
- @r.on_error { true.should == true }
556
- @r.zset_incr_by("i_am_not_a_zet", 23, "element") { false.should == true }
554
+ # shouldn't raise error anymore
555
+ @r.zset_incr_by("i_am_not_a_zet", 23, "element") { |r| r.should == nil }
557
556
 
558
557
  @r.delete("hackers")
559
558
  @r.delete("i_am_not_a_zet") { done }
@@ -644,4 +643,27 @@ EM.describe EM::Protocols::Redis do
644
643
  # # lambda { @r.sync }.should.raise
645
644
  # done
646
645
  # end
647
- end
646
+
647
+ it "should work with 10 commands" do
648
+ @r.call_commands((1..10).map { |i|
649
+ ['get', "foo"]
650
+ }) do |rs|
651
+ rs.length.should == 10
652
+ rs.each { |r| r.should == "bar" }
653
+ done
654
+ end
655
+ end
656
+ it "should work with 1 command" do
657
+ @r.call_commands([['get', "foo"]]) do |rs|
658
+ rs.length.should == 1
659
+ rs[0].should == "bar"
660
+ done
661
+ end
662
+ end
663
+ it "should work with zero commands" do
664
+ @r.call_commands([]) do |rs|
665
+ rs.should == []
666
+ done
667
+ end
668
+ end
669
+ end
data/spec/test_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../lib/em-redis")
2
+ require 'bacon'
2
3
  require 'em-spec/bacon'
3
4
 
4
5
  EM.spec_backend = EventMachine::Spec::Bacon
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superfeedr-em-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Broad
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-03-31 00:00:00 +02:00
14
+ date: 2010-04-01 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: "0"
45
+ version: 0.2.1
46
46
  version:
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bones
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: 3.4.1
56
56
  version:
57
- description: An eventmachine-based implementation of the Redis protocol
57
+ description: An eventmachine-based implementation of the Redis protocol (forked)
58
58
  email: stephan@spaceboyz.net
59
59
  executables: []
60
60
 
@@ -64,6 +64,7 @@ extra_rdoc_files:
64
64
  - History.txt
65
65
  - README.rdoc
66
66
  files:
67
+ - .gitignore
67
68
  - History.txt
68
69
  - README.rdoc
69
70
  - Rakefile
@@ -74,7 +75,7 @@ files:
74
75
  - spec/redis_protocol_spec.rb
75
76
  - spec/test_helper.rb
76
77
  has_rdoc: true
77
- homepage: http://github.com/libc/em-redis
78
+ homepage: http://github.com/astro/em-redis
78
79
  licenses: []
79
80
 
80
81
  post_install_message:
@@ -101,6 +102,6 @@ rubyforge_project: superfeedr-em-redis
101
102
  rubygems_version: 1.3.5
102
103
  signing_key:
103
104
  specification_version: 3
104
- summary: An eventmachine-based implementation of the Redis protocol
105
+ summary: An eventmachine-based implementation of the Redis protocol (forked)
105
106
  test_files: []
106
107