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


PHP Redis::watch方法代码示例

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


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

示例1: update

 /**
  * {@inheritdoc}
  */
 public function update($key, callable $modifier, $ttl = 0)
 {
     $this->redis->watch($key);
     $data = $this->redis->get($key);
     if ($data === false) {
         $this->redis->unwatch();
         return false;
     } else {
         $modifier($data);
         if ($this->setInTransaction($key, $data, (int) $ttl)) {
             return $data;
         }
     }
     throw new AtomicViolationException("Atomic violation occurred when updating key \"{$key}\".");
 }
开发者ID:lingualeo,项目名称:php-cache,代码行数:18,代码来源:RedisCache.php

示例2: testMultiExec

 public function testMultiExec()
 {
     $this->sequence(Redis::MULTI);
     $this->differentType(Redis::MULTI);
     // with prefix as well
     $this->redis->setOption(Redis::OPT_PREFIX, "test:");
     $this->sequence(Redis::MULTI);
     $this->differentType(Redis::MULTI);
     $this->redis->setOption(Redis::OPT_PREFIX, "");
     $this->redis->set('x', '42');
     $this->assertTrue(TRUE === $this->redis->watch('x'));
     $ret = $this->redis->multi()->get('x')->exec();
     // successful transaction
     $this->assertTrue($ret === array('42'));
     // failed transaction
     $this->redis->watch('x');
     $r = $this->newInstance();
     // new instance, modifying `x'.
     $r->incr('x');
     $ret = $this->redis->multi()->get('x')->exec();
     $this->assertTrue($ret === FALSE);
     // failed because another client changed our watched key between WATCH and EXEC.
     // watch and unwatch
     $this->redis->watch('x');
     $r->incr('x');
     // other instance
     $this->redis->unwatch();
     // cancel transaction watch
     $ret = $this->redis->multi()->get('x')->exec();
     $this->assertTrue($ret === array('44'));
     // succeeded since we've cancel the WATCH command.
 }
开发者ID:stonegithubs,项目名称:phpredis,代码行数:32,代码来源:TestRedis.php

示例3: mget

 protected function mget()
 {
     $this->db->watch([$this->count]);
     $error = $this->db->getLastError();
     if ($error) {
         return $error;
     }
     $replies = $this->db->mGet([$this->count, $this->limit, $this->reset]);
     $error = $this->db->getLastError();
     if ($error) {
         return $error;
     }
     if (!$replies[0] && $replies[0] !== '0') {
         return $this->create();
     }
     return $this->decr($replies);
 }
开发者ID:leilt331,项目名称:rest_api,代码行数:17,代码来源:RateLimiter.php

示例4: freeze

 /**
  * Freezes this cache backend.
  *
  * All data in a frozen backend remains unchanged and methods which try to add
  * or modify data result in an exception thrown. Possible expiry times of
  * individual cache entries are ignored.
  *
  * A frozen backend can only be thawn by calling the flush() method.
  *
  * @throws \RuntimeException
  * @return void
  */
 public function freeze()
 {
     if ($this->isFrozen()) {
         throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
     }
     do {
         $entriesKey = $this->buildKey('entries');
         $this->redis->watch($entriesKey);
         $entries = $this->redis->lRange($entriesKey, 0, -1);
         $this->redis->multi();
         foreach ($entries as $entryIdentifier) {
             $this->redis->persist($this->buildKey('entry:' . $entryIdentifier));
         }
         $this->redis->set($this->buildKey('frozen'), 1);
         $result = $this->redis->exec();
     } while ($result === false);
     $this->frozen = true;
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:30,代码来源:RedisBackend.php

示例5: testFailedTransactions

 public function testFailedTransactions()
 {
     $this->redis->set('x', 42);
     // failed transaction
     $this->redis->watch('x');
     $r = $this->newInstance();
     // new instance, modifying `x'.
     $r->incr('x');
     $ret = $this->redis->multi()->get('x')->exec();
     $this->assertTrue($ret === FALSE);
     // failed because another client changed our watched key between WATCH and EXEC.
     // watch and unwatch
     $this->redis->watch('x');
     $r->incr('x');
     // other instance
     $this->redis->unwatch();
     // cancel transaction watch
     $ret = $this->redis->multi()->get('x')->exec();
     $this->assertTrue($ret === array('44'));
     // succeeded since we've cancel the WATCH command.
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:21,代码来源:RedisTest.php

示例6: tryLock

 protected function tryLock()
 {
     $this->redis->watch('lock');
     $result = $this->redis->blPop(array('lock'), static::LOCK_TIMEOUT);
     return !empty($result);
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:6,代码来源:RedisQueue.php

示例7:

$key = 'test-expire-key';
$redis->expire($key, 60);
//使用秒为单位
$redis->pExpire($key, 60000);
//使用毫秒作为单位
$redis->expireAt($key, 1476868380);
//使用Unix timestamp,指定时间过期
$redis->pExpireAt($key, 1476868380000.0);
//使用Unix timestamp在指定时间过期,区别是毫秒作为单位
$redis->persist($key);
//移除给定key的生存时间
$redis->ttl($key);
//返回key剩余的过期时间,使用秒为单位
$redis->pttl($key);
//返回key剩余的过期时间,使用毫秒作为单位
$redis->watch($key2);
$ret = $redis->multi(Redis::MULTI)->get($key)->incr($key1)->del($key2)->exec();
$pip->incr('a');
$pip->get('test-num2');
$pip->incr('b');
$pip->del('a');
$ret = $pip->exec();
var_dump($ret);
exit;
$ret = $redis->incr('test-num2')->incr('test-num2')->exec();
exit('aa' . $redis->get('test-num2'));
$redis->multi(Redis::PIPELINE);
for ($i = 0; $i < 10000; $i++) {
    $redis->incr('test-num')->include('test-num2');
}
$redis->exec();
开发者ID:xiehaowei,项目名称:php,代码行数:31,代码来源:redis.php

示例8: PDO

<?php

/*
$dsn = "mysql:host=localhost;dbname=demo";
$db = new PDO($dsn, 'root', 'root');
*/
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->watch('myk');
$vn = $redis->get('myk');
$vn = $vn + 1;
sleep(1);
$redis->multi();
$redis->set('myk', $vn);
$rs = $redis->exec();
if (!$rs) {
    error_log("eeee\n", 3, 'F:/logdata/eee.log');
}
开发者ID:ruyicoder,项目名称:php,代码行数:18,代码来源:ab_watch.php

示例9: removeExpiredJobs

 /**
  * Remove the expired jobs from a given queue.
  *
  * @param  \Redis  $transaction
  * @param  string  $from
  * @param  int  $time
  * @return void
  */
 protected function removeExpiredJobs($transaction, $from, $time)
 {
     $transaction->watch($from);
     $transaction->multi();
     $transaction->zRemRangeByScore($from, '-inf', $time);
 }
开发者ID:targetliu,项目名称:phpredis,代码行数:14,代码来源:PHPRedisQueue.php


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