コード例 #1
0
 public function testZScan()
 {
     $this->redis->del('testZScan');
     $key = 'testZScan';
     $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3'];
     foreach ($members as $member) {
         $this->redis->zAdd($key, 1.0, $member);
     }
     // a bit tricky to test, since we can't determine the outcome of a single iteration (or can we?)
     // so we just iterate until the iterator is exhausted and then compare the final results
     $iterator = 0;
     // we unroll the iteration here, to have better control over the involved values
     $result = $this->redis->zScan($key, $iterator);
     $this->assertNotEmpty($result);
     foreach ($members as $member) {
         $this->assertArrayHasKey($member, $result);
     }
     $this->assertSame(15, count($result));
     $this->assertSame(0, $iterator);
     $smembers = $this->redis->zRange($key, 0, 100, true);
     ksort($smembers);
     ksort($result);
     $this->assertSame($smembers, $result);
     $result1 = $this->redis->zScan($key, $iterator, 'testScanH?llo', 20);
     $this->assertArrayHasKey('testScanHello', $result1);
     $this->assertArrayHasKey('testScanHallo', $result1);
     $this->assertEquals(2, count($result1));
     $this->assertSame(0, $iterator);
 }
コード例 #2
0
ファイル: TryCatchWrapper.php プロジェクト: plista/core-redis
 /**
  * Adds the specified members with a given score to the sorted set stored at key.
  *
  * @param string $key Required key
  * @param array|float $score Required score or array of value=>score pairs
  * @param string $value Required value if $score is passed as float
  *
  * @return int Number of values added
  * @link http://redis.io/commands/zadd
  * @example
  * <pre>
  * <pre>
  * $redis->zAdd('z', array('v2' => 1, 'v2', => 2, 'v3' => 3, 'v4' => 4); // int(3)
  * $redis->zRem('z', 'v2', 'v3'); // int(2)
  * var_dump( $redis->zRange('z', 0, -1) );
  * //// Output:
  * // array(2) {
  * // [0]=> string(2) "v4"
  * // }
  * </pre>
  * </pre>
  */
 public function zAdd($key, $score, $value = null)
 {
     try {
         return $this->client->zAdd($key, $score, $value);
     } catch (Exception $e) {
         return $this->handleException($e, __FUNCTION__, func_get_args());
     }
 }
コード例 #3
0
 public function zAdd($key, $score, $value = null)
 {
     $args = func_get_args();
     if (count($args) > 3) {
         $this->signalError('Call to zAdd() with more than 3 arguments.');
         // shift off key
         array_shift($args);
         // construct the array of value=>score pairs
         $combined = array();
         for ($i = 0, $count = count($args); $i < $count; $i += 2) {
             $combined[$args[$i + 1]] = $args[$i];
         }
         return $this->redis->zAdd($key, $combined);
     }
     if (!is_array($score)) {
         return $this->redis->zAdd($key, array($value => $score));
     }
     return $this->redis->zAdd($key, $score);
 }
コード例 #4
0
 /**
  * Adds the specified members with a given score to the sorted set stored at key.
  *
  * @param string $key Required key
  * @param array|float $score Required score or array of value=>score pairs
  * @param string $value Required value if $score is passed as float
  *
  * @return int Number of values added
  * @link http://redis.io/commands/zadd
  * @example
  * <pre>
  * <pre>
  * $redis->zAdd('z', array('v2' => 1, 'v2', => 2, 'v3' => 3, 'v4' => 4); // int(3)
  * $redis->zRem('z', 'v2', 'v3'); // int(2)
  * var_dump( $redis->zRange('z', 0, -1) );
  * //// Output:
  * // array(2) {
  * // [0]=> string(2) "v4"
  * // }
  * </pre>
  * </pre>
  */
 public function zAdd($key, $score, $value = null)
 {
     $this->appendToLog('ZADD ' . $key . ' ' . (is_array($score) ? implode(',', $score) : $score) . ' ' . $value);
     return $this->client->zAdd($key, $score, $value);
 }