这是我最近实施的:
try {
// Trying to acquiring lock.
// If lock is already acquired, waiting 5 seconds to try again.
Cache::lock($key)->block(5);
} catch (LockTimeoutException $e) {
// Unable to acquire lock, can't cache the token
return;
}
// Lock acquired, caching the token
Cache::put($key, $token, 1);
Run Code Online (Sandbox Code Playgroud)
为了测试这一点,我们使用了两台设备以同一用户身份登录并同时发出相同的请求。希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
1687 次 |
| 最近记录: |