Class: MySQLNoIo::Wraps::GlobalLock
- Inherits:
-
Object
- Object
- MySQLNoIo::Wraps::GlobalLock
- Defined in:
- lib/mysqlnoio/wraps/global_lock.rb
Overview
Allows you to run commands against a MySQL database, while MySQL’s tables are locked, and the tables are flushed.
Instance Method Summary collapse
-
#execute(&block) ⇒ Object
Lock the tables, run our command, and then unlock the tables.
-
#initialize(mysql) ⇒ GlobalLock
constructor
Prepare to set up the GlobalLock wrapper, with the mysql2 connection.
Constructor Details
#initialize(mysql) ⇒ GlobalLock
Prepare to set up the GlobalLock wrapper, with the mysql2 connection
7 8 9 |
# File 'lib/mysqlnoio/wraps/global_lock.rb', line 7 def initialize mysql @mysql = mysql end |
Instance Method Details
#execute(&block) ⇒ Object
Lock the tables, run our command, and then unlock the tables.
12 13 14 15 16 17 |
# File 'lib/mysqlnoio/wraps/global_lock.rb', line 12 def execute &block @mysql.query("FLUSH TABLES WITH READ LOCK;") yield ensure @mysql.query("UNLOCK TABLES;") end |