本文整理匯總了PHP中Illuminate\Support\Facades\Cache::increment方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cache::increment方法的具體用法?PHP Cache::increment怎麽用?PHP Cache::increment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\Cache
的用法示例。
在下文中一共展示了Cache::increment方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: incrementLoginAttempts
protected function incrementLoginAttempts(Request $request)
{
$key = $this->getLoginAttemptsKey($request);
if (!Cache::has($key)) {
Cache::add($key, 1, static::LOGIN_LOCKOUT_MINUTES);
return 1;
}
return (int) Cache::increment($key);
}
示例2: getPaymentSerialNumber
/**
*
* 生成流水號算法:第1位為支付渠道,2-7位為日期,8-17位是當日流水經過Skip32加密過的流水號,可解密出真實流水。最後3位為隨機數。
* @param $prefix 1位數字,標記支付類型.1:微信支付,2:支付寶支付,3:銀聯支付
* @return string
*/
public static function getPaymentSerialNumber($prefix)
{
$timestamp = time();
$datePrefix = date('ymd', $timestamp);
$key = self::CACHE_KEY_PAYMENT_COUNT . $datePrefix;
if (!Cache::has($key)) {
$counter = Payment::getTodayCount();
$expiresAt = Carbon::now()->addMinutes(1440);
Cache::put($key, $counter, $expiresAt);
}
$value = Cache::increment($key);
$value = str_pad(Skip32::encrypt(self::ENCRYPTED_KEY, $value), 10, '0', STR_PAD_LEFT);
return $prefix . $datePrefix . $value . str_pad(rand(0, 999), 3, '0', STR_PAD_LEFT);
}
示例3: incrementLoginAttempts
/**
* Increment the login attempts for the user.
*
* @param \Illuminate\Http\Request $request
* @return int
*/
protected function incrementLoginAttempts(Request $request)
{
Cache::add($key = $this->getLoginAttemptsKey($request), 1, 1);
return (int) Cache::increment($key);
}
示例4: incView
/**
* increase view count
*/
private function incView()
{
if (!$this->cacheViewName) {
$viewsCount = $this->views_count();
}
$viewsCount = Cache::increment($this->cacheViewName, Config::get('counter.viewIncrementAmount', 1));
$this->setViewed();
$this->regularCheck($viewsCount, 'view');
return $viewsCount;
}
示例5: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (Cache::get('isWorkerStarted', false)) {
return;
}
if (!Cache::get('isProcessing', false)) {
return;
}
Cache::forever('isWorkerStarted', true);
set_time_limit(0);
$skipTables = explode(',', env('SKIP_TABLES', ''));
if (Cache::has('tables')) {
$tables = Cache::get('tables');
} else {
$tables = ['pgsql' => [], 'mongodb' => []];
$pgsqlTables = DB::connection('pgsql')->getDoctrineSchemaManager()->listTableNames();
foreach ($pgsqlTables as $table) {
$tables['pgsql'][] = str_replace('"', '', $table);
}
$tables['mongodb'] = DB::connection('mongodb')->getMongoDB()->getCollectionNames();
Cache::put('tables', $tables, 15);
}
if (Cache::has('rows')) {
$rows = Cache::get('rows');
} else {
$rows = ['pgsql' => [], 'mongodb' => []];
foreach ($tables['pgsql'] as $table) {
if (in_array($table, $skipTables)) {
$rows['pgsql'][$table] = 0;
continue;
}
$rows['pgsql'][$table] = DB::connection('pgsql')->table($table)->count();
}
foreach ($tables['mongodb'] as $table) {
$rows['mongodb'][$table] = DB::connection('mongodb')->table($table)->raw(function ($collection) {
return $collection->count();
});
}
Cache::put('rows', $rows, 15);
}
$runStartedAt = time();
$wasWorking = false;
while ($runStartedAt + 60 * 10 >= time()) {
foreach ($tables['pgsql'] as $table) {
if (!Schema::connection('mongodb')->hasCollection($table)) {
Schema::connection('mongodb')->create($table);
$tables['mongodb'][] = $table;
$rows['mongodb'][$table] = 0;
Cache::put('tables', $tables, 15);
Cache::put('rows', $rows, 15);
}
if (in_array($table, $skipTables)) {
continue;
}
if ($rows['pgsql'][$table] > $rows['mongodb'][$table]) {
$batchSize = 10000;
DB::connection('mongodb')->disableQueryLog();
DB::connection('pgsql')->disableQueryLog();
$data = DB::connection('pgsql')->table($table)->skip($rows['mongodb'][$table])->take($batchSize)->get();
$insert = json_decode(json_encode($data), true);
// Cast date fields to MongoDate objects
foreach ($insert as $key => $item) {
foreach ($item as $rowName => $value) {
if ($rowName == 'created_at' || $rowName == 'updated_at') {
$insert[$key][$rowName] = new MongoDate(strtotime($value));
}
}
}
DB::connection('mongodb')->table($table)->insert($insert);
$rows['mongodb'][$table] += $batchSize;
if ($rows['mongodb'][$table] > $rows['pgsql'][$table]) {
$rows['mongodb'][$table] = $rows['pgsql'][$table];
}
Cache::put('rows', $rows, 15);
Cache::increment('rowsProcessedThisRun', $batchSize);
$wasWorking = true;
break;
}
}
}
if ($wasWorking == false) {
Cache::forever('timeFinished', Carbon::now());
Cache::forever('isProcessing', false);
}
Cache::forever('isWorkerStarted', false);
}