當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Cache::increment方法代碼示例

本文整理匯總了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);
 }
開發者ID:SerdarSanri,項目名稱:laravel-auth-pack,代碼行數:9,代碼來源:ThrottlesLoginsTrait.php

示例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);
 }
開發者ID:hachi-zzq,項目名稱:dajiayao,代碼行數:20,代碼來源:OrderHelper.php

示例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);
 }
開發者ID:MachiavelliQ,項目名稱:www,代碼行數:11,代碼來源:ThrottlesLogins.php

示例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;
 }
開發者ID:jacobcyl,項目名稱:laravel-counter,代碼行數:13,代碼來源:ViewCounterTrait.php

示例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);
 }
開發者ID:unknownworlds,項目名稱:postgre2mongo,代碼行數:91,代碼來源:Process.php


注:本文中的Illuminate\Support\Facades\Cache::increment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。