当前位置: 首页>>代码示例>>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;未经允许,请勿转载。