当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::transaction方法代码示例

本文整理汇总了PHP中Predis\Client::transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::transaction方法的具体用法?PHP Client::transaction怎么用?PHP Client::transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Predis\Client的用法示例。


在下文中一共展示了Client::transaction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: remove

 /**
  * @param User $user
  */
 public function remove(User $user)
 {
     $this->redisClient->transaction(function (MultiExec $tx) use($user) {
         $id = $user->getId();
         $tx->hdel(self::USER_HASH_STORE, $id);
         if (!empty($user->getGithubId())) {
             $tx->hdel('github_' . self::USER_HASH_STORE, $user->getGithubId());
         }
         if (!empty($user->getGoogleId())) {
             $tx->hdel('google_' . self::USER_HASH_STORE, $user->getGoogleId());
         }
         if (!empty($user->getBitbucketId())) {
             $tx->hdel('bitbucket_' . self::USER_HASH_STORE, $user->getBitbucketId());
         }
     });
 }
开发者ID:Doanlmit,项目名称:pickleweb,代码行数:19,代码来源:UserRepository.php

示例2: incrementAndCount

 /**
  * Calls the increment() and count() function using a single MULTI/EXEC block.
  *
  * @param string $subject  A unique identifier, for example a session id or an IP
  * @param int    $interval Interval in seconds
  *
  * @return int
  */
 public function incrementAndCount($subject, $interval)
 {
     $bucket = $this->getBucket();
     $subject = $this->key . ':' . $subject;
     $count = (int) floor($interval / $this->bucketInterval);
     $multi = $this->client->transaction();
     $this->addMultiExecIncrement($multi, $subject, $bucket);
     $this->addMultiExecCount($multi, $subject, $bucket, $count);
     return array_sum(array_slice($multi->exec(), 4));
 }
开发者ID:Pouix,项目名称:SncRedisBundle,代码行数:18,代码来源:RateLimit.php

示例3: pop

 /**
  * @inheritdoc
  */
 public function pop($queue)
 {
     foreach ([':delayed', ':reserved'] as $type) {
         $options = ['cas' => true, 'watch' => $queue . $type];
         $this->redis->transaction($options, function (MultiExec $transaction) use($queue, $type) {
             $data = $this->redis->zrangebyscore($queue . $type, '-inf', $time = time());
             if (!empty($data)) {
                 $transaction->zremrangebyscore($queue . $type, '-inf', $time);
                 $transaction->rpush($queue, $data);
             }
         });
     }
     $data = $this->redis->lpop($queue);
     if ($data === null) {
         return false;
     }
     $this->redis->zadd($queue . ':reserved', [$data => time() + $this->expire]);
     $data = Json::decode($data);
     return ['id' => $data['id'], 'body' => $data['body'], 'queue' => $queue];
 }
开发者ID:Nuffic,项目名称:yii2-queue-1,代码行数:23,代码来源:RedisQueue.php

示例4: 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

示例5: save

 /**
  * @param object $object
  */
 public function save($object)
 {
     if (!is_object($object)) {
         throw new InvalidArgumentException(sprintf('You must pass an object to Tystr\\RedisOrm\\Repository\\PredisRepository::save(), %s given.', gettype($object)));
     }
     $metadata = $this->getMetadataFor($this->className);
     $key = $this->keyNamingStrategy->getKeyName(array($metadata->getPrefix(), $this->getIdForClass($object, $metadata)));
     $originalData = $this->redis->hgetall($key);
     $transaction = $this->redis->transaction();
     $transaction->hmset($key, $newData = $this->hydrator->toArray($object, $metadata));
     // @todo compute changeset here
     $this->handleProperties($object, $metadata, $originalData, $newData, $transaction);
     $transaction->execute();
 }
开发者ID:tystr,项目名称:redis-orm,代码行数:17,代码来源:ObjectRepository.php

示例6: purge

 /**
  * {@inheritdoc}
  */
 protected function purge()
 {
     try {
         $this->client->transaction(function ($tx) {
             $keyPrefix = $this->client->getOptions()->prefix;
             foreach (new \Predis\Collection\Iterator\Keyspace($this->client, '*') as $key) {
                 $tx->del(substr($key, strlen($keyPrefix)));
             }
         });
     } catch (\Predis\Transaction\AbortedMultiExecException $e) {
         return false;
     }
     return true;
 }
开发者ID:autocom,项目名称:smarty-redis,代码行数:17,代码来源:CacheResource.php

示例7: setCurrentValue

 /**
  * @param $key
  * @param $value
  * @param $expire
  * @param $now
  */
 private function setCurrentValue($namespace, $key, $value, $expire = 0)
 {
     $namespaceKey = $this->buildNamespaceKey($namespace, $key);
     $currentKey = $this->buildCurrentKey($namespaceKey);
     $previousKey = $this->buildPreviousKey($namespaceKey);
     list($previousValue, , ) = $this->redis->transaction(function (MultiExec $tx) use($currentKey, $previousKey, $value, $expire) {
         $tx->get($previousKey);
         $tx->set($currentKey, $value);
         if ($expire > 0) {
             $tx->expire($currentKey, $expire);
         }
     });
     $this->previousValues[$namespaceKey] = $previousValue;
     $this->currentValues[$namespaceKey] = $value;
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:21,代码来源:StateMachine.php

示例8: flush

 /**
  *
  */
 public function flush()
 {
     $this->client->transaction(function () {
         foreach ($this->buffer as $name => $options) {
             $ttl = $this->client->ttl($name);
             $exists = $this->client->exists($name);
             $this->client->set($name, $options['value']);
             if ($options['expire'] > 0) {
                 $this->client->expire($name, $options['expire']);
             }
             if ($options['expire'] < 0) {
                 if (!$exists || $ttl < 0) {
                     $this->client->expireat($name, time() + $options['expire'] * -1);
                 } else {
                     $this->client->expire($name, $ttl);
                 }
             }
         }
     });
 }
开发者ID:jced-artem,项目名称:test_game,代码行数:23,代码来源:Cache.php

示例9: set

 /**
  * @param Session $session
  */
 public function set(Session $session)
 {
     $sid = $session->getSessionId();
     $redisId = $this->buildKey($sid);
     if ($session->shouldKill()) {
         $this->redis->del($redisId);
     } else {
         $this->redis->transaction(function (MultiExec $tx) use($session, $redisId) {
             foreach ($session->getDeletedKeys() as $key) {
                 $tx->hdel($redisId, $key);
             }
             $changes = $session->getChanges();
             if (count($changes) > 0) {
                 $tx->hmset($redisId, $session->getChanges());
             }
             // session regeneration is not supported
             $tx->expire($redisId, $this->getExpires());
         });
         $this->oracleKeepAlive($sid);
     }
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:24,代码来源:OracleHookedRedisSessionProvider.php

示例10: set

 /**
  * @param Session $session
  */
 public function set(Session $session)
 {
     $redisId = $this->buildKey($session->getSessionId());
     if ($session->shouldKill()) {
         $this->redis->del($redisId);
     } else {
         $this->redis->transaction(function (MultiExec $tx) use($session, $redisId) {
             foreach ($session->getDeletedKeys() as $key) {
                 $tx->hdel($redisId, $key);
             }
             $changes = $session->getChanges();
             if (count($changes) > 0) {
                 $tx->hmset($redisId, $session->getChanges());
             }
             if ($session->shouldRegenerate()) {
                 $session->setSid(UUID::v4());
                 $newRedisId = $this->buildKey($session->getSessionId());
                 $tx->rename($redisId, $newRedisId);
                 $redisId = $newRedisId;
             }
             $tx->expire($redisId, $this->getExpires());
         });
     }
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:27,代码来源:RedisSessionProvider.php

示例11: testMethodTransactionIsAliasForMethodMultiExec

 /**
  * @group disconnected
  */
 public function testMethodTransactionIsAliasForMethodMultiExec()
 {
     $client = new Client();
     $this->assertInstanceOf('Predis\\Transaction\\MultiExecContext', $client->transaction());
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:8,代码来源:ClientTest.php

示例12: testTransactionWithArrayAndCallableExecutesMultiExec

 /**
  * @group disconnected
  */
 public function testTransactionWithArrayAndCallableExecutesMultiExec()
 {
     // We use CAS here as we don't care about the actual MULTI/EXEC context.
     $options = array('cas' => true, 'retry' => 3);
     $connection = $this->getMock('Predis\\Connection\\NodeConnectionInterface');
     $connection->expects($this->once())->method('executeCommand')->will($this->returnValue(new Response\Status('QUEUED')));
     $txCallback = function ($tx) {
         $tx->ping();
     };
     $callable = $this->getMock('stdClass', array('__invoke'));
     $callable->expects($this->once())->method('__invoke')->will($this->returnCallback($txCallback));
     $client = new Client($connection);
     $client->transaction($options, $callable);
 }
开发者ID:pikniktech,项目名称:dailybriefweb2,代码行数:17,代码来源:ClientTest.php

示例13: getAndDeleteKey

 public function getAndDeleteKey($key)
 {
     $responses = $this->_client->transaction()->get($key)->del(array($key))->execute();
     return $responses[0];
 }
开发者ID:Antevenio,项目名称:redis,代码行数:5,代码来源:Client.php


注:本文中的Predis\Client::transaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。