lib/em-hiredis/base_client.rb in gilmour-em-hiredis-0.3.0 vs lib/em-hiredis/base_client.rb in gilmour-em-hiredis-0.3.1

- old
+ new

@@ -208,11 +208,18 @@ deferred = EM::DefaultDeferrable.new # Shortcut for defining the callback case with just a block deferred.callback { |result| yield(result) } if block_given? if @connected - @connection.send_command(sym, args) - @defs.push(deferred) + res = @connection.send_command(sym, args) + # @connected can be in a stale state. send_command will fail and return + # 0 (if EM pure_ruby implmentation is not used). In that case, queue up + # the command once to be retried on reconnection + if res && res.kind_of?(Numeric) && res == 0 + @command_queue << [deferred, sym, args] + else + @defs.push(deferred) + end elsif @failed deferred.fail(Error.new("Redis connection in failed state")) else @command_queue << [deferred, sym, args] end