简体   繁体   中英

The meaning of lock ending with exclamation mark

I tried to find on internet, but I could find a good explanation. What does lock ending with exclamation mark mean in ruby? eg @student.lock! (BTW, I know what lock means in concurrency)

Go to the Ruby on Rails site. Click on the " API " link at the top. Type "lock!" into the search field. Click on the first result .

ActiveRecord :: Locking :: Pessimistic#lock!

lock!(lock = true)

Obtain a row lock on this record. Reloads the record to obtain the requested lock. Pass an SQL locking clause to append the end of the SELECT statement or pass true for “FOR UPDATE” (the default, an exclusive row lock). Returns the locked record.

If you're unclear on what a row lock is, the first half of this article is a good place to start. The TL;DR is that a row lock prevents some other database user (which might be another connection from the same app) from modifying the row you're modifying or about to modify.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM