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


PHP Client::setnx方法代碼示例

本文整理匯總了PHP中Predis\Client::setnx方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::setnx方法的具體用法?PHP Client::setnx怎麽用?PHP Client::setnx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Predis\Client的用法示例。


在下文中一共展示了Client::setnx方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add

 public function add($id, $value, $ttl = null)
 {
     try {
         $this->redis->setnx($id, $value);
         if ($ttl) {
             $this->redis->expire($id, $ttl);
         }
         return true;
     } catch (Predis\PredisException $e) {
         return false;
     }
 }
開發者ID:maximebf,項目名稱:cachecache,代碼行數:12,代碼來源:Redis.php

示例2: initializeRedis

 /**
  * Make sure, the Redis keys exist.
  *
  * @return void
  */
 private function initializeRedis()
 {
     if ($this->initialized) {
         return;
     }
     $this->hash = substr(sha1(serialize($this->items)), 0, 8);
     $positionKey = $this->getKeyForCurrentPosition();
     $existing = !$this->redis->setnx($positionKey, count($this->items) - 1);
     if (!$existing && count($this->items)) {
         $listKey = $this->getKeyForItemList();
         $this->itemCount = $this->redis->rpush($listKey, $this->items);
     }
     $this->initialized = true;
 }
開發者ID:battlerattle,項目名稱:shuffle-bag,代碼行數:19,代碼來源:RedisStorage.php

示例3: work

 public function work()
 {
     foreach ($this->limits as $index => $limit) {
         $counterName = "queue:{$this->tube}:throttle:{$index}";
         $started = (bool) $this->redis->setnx($counterName, $limit['requests']);
         $counter = $this->redis->get($counterName);
         if ($started) {
             $this->redis->transaction(function (MultiExec $transaction) use($counterName, $limit) {
                 $transaction->expire($counterName, $limit['seconds']);
                 $transaction->decr($counterName);
             });
         } else {
             if ($counter > 1) {
                 $this->redis->decr($counterName);
             } else {
                 $this->pheanstalk->pauseTube($this->tube, $this->redis->ttl($counterName));
             }
         }
     }
 }
開發者ID:likewinter,項目名稱:queue-throttle,代碼行數:20,代碼來源:Throttle.php

示例4: lockSession

 private function lockSession($sessionId)
 {
     $attempts = 1000000 / $this->spinLockWait * $this->lockMaxWait;
     $this->lockKey = $sessionId . '.lock';
     for ($i = 0; $i < $attempts; $i++) {
         $success = $this->redis->setnx($this->prefix . $this->lockKey, '1');
         if ($success) {
             $this->locked = true;
             $this->redis->expire($this->prefix . $this->lockKey, $this->lockMaxWait + 1);
             return true;
         }
         usleep($this->spinLockWait);
     }
     return false;
 }
開發者ID:headzoo,項目名稱:redis-bundle,代碼行數:15,代碼來源:RedisSessionHandler.php

示例5: useNonce

 /**
  * Create nonce for server and salt, expiring after 
  * $Auth_OpenID_SKEW seconds.
  */
 function useNonce($server_url, $timestamp, $salt)
 {
     global $Auth_OpenID_SKEW;
     // save one request to memcache when nonce obviously expired
     if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
         return false;
     }
     // SETNX will set the value only of the key doesn't exist yet.
     $nonceKey = $this->nonceKey($server_url, $salt);
     $added = $this->redis->setnx($nonceKey, "1");
     if ($added) {
         // Will set expiration
         $this->redis->expire($nonceKey, $Auth_OpenID_SKEW);
         return true;
     } else {
         return false;
     }
 }
開發者ID:openid,項目名稱:php-openid,代碼行數:22,代碼來源:PredisStore.php


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