久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel lockforupdate(悲觀鎖)

Laravel lockforupdate (Pessimistic Locking)(Laravel lockforupdate(悲觀鎖))
本文介紹了Laravel lockforupdate(悲觀鎖)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試弄清楚如何正確使用/測試 lockforupdate,但我發現它的功能與我預期的不一樣

這只是測試

公共函數索引(){返回 dd(DB::transaction(function() {如果 (Auth::guard('user')->check()) {$model = AppModelsUser::find(1)->lockForUpdate();睡眠(60);$model->point = 100000;$model->save();} 別的 {$model = AppModelsUser::find(1);$model->point = 999;$model->save();}返回 $model;}));}

我嘗試在 2 個瀏覽器中進行測試,瀏覽器 1 用戶登錄而瀏覽器 2 未登錄,瀏覽器 1 刷新,然后會在更新前鎖定更新并休眠 60 秒

在 60 秒內,我轉到瀏覽器 2 并刷新,但是記錄沒有鎖定,我檢查 phpmyadmin 并更新記錄(在瀏覽器 1 觸發的 60 秒鎖定內)

但是60秒后,記錄又被瀏覽器1修改了(Point 100000)

我是不是誤解了 lockforupdate 的用途?還是我測試錯誤?

我期望的是瀏覽器 2 在前 60 秒內不應修改該行(帶有加載圖標或錯誤拋出的空白頁面?)

https://laravel.com/docs/5.2/queries#pessimistic-locking

我做了一些研究,但仍然無法理解 sharedLock(LOCK IN SHARE MODE) 和 lockForUpdate(FOR UPDATE) 之間的區別

順便說一句,我確認數據庫是 innodb

解決方案

這個工作,終于,但還是沒明白sharedLock(LOCK IN SHARE MODE)和lockForUpdate(FOR UPDATE)有什么不同

 公共函數 index() {返回 dd(DB::transaction(function() {如果 (Auth::guard('user')->check()) {$model = AppModelsUser::lockForUpdate()->find(1);睡眠(30);$model->point = 100000;$model->save();} 別的 {$model = AppModelsUser::lockForUpdate()->find(1);$model->point = $model->point + 1;$model->save();}返回 $model;}));}

i'm trying to figure out how to use/test the lockforupdate correctly, but i found is not function like what i expected

this is just testing

public function index() {
        return dd(DB::transaction(function() {
            if (Auth::guard('user')->check()) {
                $model = AppModelsUser::find(1)->lockForUpdate();
                sleep(60);
                $model->point = 100000;
                $model->save();
            } else {
                $model = AppModelsUser::find(1);
                $model->point = 999;
                $model->save();
            }

            return $model;
        }));
}

i try to test in 2 browser, browser 1 user logged in and browser 2 not logged in, browser 1 hit refresh, then there will lockforupdate and sleep 60 seconds before update

in the 60 seconds, i go browser 2 and hit refresh, however the record is not locked, i check phpmyadmin and the record is updated(within the 60 seconds lock trigger by browser 1)

but after 60 seconds, the record has been modified again by browser 1(Point 100000)

so am i misunderstanding the lockforupdate is use for?or i test it incorrectly?

what i expected is the row shouldn't be modified by browser 2 in the first 60 seconds(blank page with loading favicon or error throw?)

https://laravel.com/docs/5.2/queries#pessimistic-locking

and i did some research but still cannot understand what different between sharedLock(LOCK IN SHARE MODE) and lockForUpdate(FOR UPDATE)

btw i confirmed the database is innodb

解決方案

This work, finally, but still don't understand what sharedLock(LOCK IN SHARE MODE) and lockForUpdate(FOR UPDATE) different

    public function index() {
        return dd(DB::transaction(function() {
            if (Auth::guard('user')->check()) {
                $model = AppModelsUser::lockForUpdate()->find(1);
                sleep(30);
                $model->point = 100000;
                $model->save();
            } else {
                $model = AppModelsUser::lockForUpdate()->find(1);
                $model->point = $model->point + 1;
                $model->save();
            }

            return $model;
        }));
    }

這篇關于Laravel lockforupdate(悲觀鎖)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Magento products by categories(按類別劃分的 Magento 產品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 一区二区在线不卡 | 91一区二区 | 久久久久久久久久久爱 | 97精品国产| 在线观看亚洲欧美 | 99国内精品久久久久久久 | 国产精品爱久久久久久久 | 伊人一二三 | 国产在线观看一区 | 成人亚洲精品 | 国产999精品久久久 日本视频一区二区三区 | 久久精品国产免费一区二区三区 | 成人在线免费视频观看 | 伊人99| 日韩成人一区 | 亚洲国产精品人人爽夜夜爽 | 一区二区不卡视频 | www.日本在线播放 | 在线免费观看黄a | 成人永久免费 | 在线视频一区二区 | 毛片网站免费观看 | 天堂在线91 | 操久久 | 国产精品久久9 | av天天干 | 国产国语精品 | 国产精品永久免费 | 久久久999成人 | 日韩一级| 欧美激情黄色 | 在线视频一区二区三区 | 国产精品污污视频 | 综合久久网 | 日韩高清国产一区在线 | 午夜爱爱网 | 久久久国产视频 | 美国黄色毛片 | www.9191.com| 99视频在线 | 国产极品91|