Permalink
Browse files

fix async auth / add in em-redis. closes #22

  • Loading branch information...
1 parent 1b932c9 commit 7e9a32d45c9854fb4df6aebca56580761dad7ac3 @igrigorik committed Mar 23, 2011
Showing with 19 additions and 6 deletions.
  1. +3 −3 lib/em-synchrony/em-redis.rb
  2. +16 −3 spec/redis_spec.rb
@@ -24,10 +24,10 @@ def self.connect(*args)
alias :old_call_command :call_command
+ SYNC = ['add', 'auth']
def call_command(argv, &blk)
- # async commands are 'a' prefixed, but do check
- # for the 'add' command corner case (ugh)
- if argv.first.size > 3 && argv.first[0] == 'a'
+ # async commands are 'a' prefixed
+ if (argv.first[0] == 'a') && !SYNC.include?(argv.first.to_s)
argv[0] = argv[0].to_s.slice(1,argv[0].size)
old_call_command(argv, &blk)
View
@@ -30,7 +30,7 @@
redis.set('mmget1', 'value1')
redis.set('mmget3', 'value3')
redis.mapped_mget('mmget1', 'mmget2', 'mmget3').should ==
- { 'mmget1' => 'value1', 'mmget3' => 'value3' }
+ { 'mmget1' => 'value1', 'mmget3' => 'value3' }
EM.stop
end
@@ -78,7 +78,7 @@
end
it "should execute async mapped_mget" do
- EventMachine.synchrony do
+ EventMachine.synchrony do
redis = EM::Protocols::Redis.connect
redis.aset('some_key', 'some_value') do
@@ -89,4 +89,17 @@
end
end
end
-end
+
+ it "should execute sync add and auth" do
+ EventMachine.synchrony do
+ redis = EM::Protocols::Redis.connect
+ redis.auth('abc')
+
+ redis.delete('key')
+ redis.add('key', 'value')
+ redis.scard('key').should == 1
+
+ EM.stop
+ end
+ end
+end

0 comments on commit 7e9a32d

Please sign in to comment.