Async MySQL driver for Ruby/Eventmachine
Pull request Compare This branch is 55 commits ahead, 1 commit behind tmm1:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
spec update readme to point to mysql2 + em-synchrony Aug 27, 2011
Rakefile rename & update readme Mar 12, 2010
VERSION bump version Oct 3, 2010
em-mysqlplus.gemspec bump version Oct 3, 2010

EM-MySQL (Plus)

mysql2 gem now ships with an EM driver - I recommend you switch & use it! And if you want synchronous API but an async driver, then take a look at em-synchrony

EventMachine wrapper for the C-based MySQL / MySQLPlus Ruby gems, which provides callbacks, errbacks and all other niceties of EventMachine while keeping the API of the original C-based MySQL gem.


  • Maintains C-based mysql gem API
  • Deferrables for every query with callback & errback
  • Connection query queue - pile 'em up!
  • Auto-reconnect on disconnects
  • Auto-retry on deadlocks

Example usage:

# gem install em-mysqlplus
# irb -r em-mysqlplus do
  conn = => 'localhost')
  query = conn.query("select 1+1")
  query.callback { |res| p res.all_hashes }
  query.errback  { |res| p res.all_hashes }

Query queueing: do
  conn = => 'localhost')

  results = []
  conn.query("select 1") {|res| results.push res.fetch_row.first.to_i}
  conn.query("select 2") {|res| results.push res.fetch_row.first.to_i}
  conn.query("select 3") {|res| results.push res.fetch_row.first.to_i}

  EventMachine.add_timer(0.05) do
    p results # => [1,2,3]


  • Original Async MySQL driver for Ruby/EventMachine - (c) 2008 Aman Gupta (tmm1)
  • ActiveRecord fiber patches - Mike Perham (mperham)