示例#1
0
 public function testHScan()
 {
     $this->redis->del('testHScan');
     $key = 'testHScan';
     $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3'];
     foreach ($members as $member) {
         $this->redis->hSet($key, $member, 'someValue');
     }
     // 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->hScan($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->hGetAll($key);
     ksort($smembers);
     ksort($result);
     $this->assertSame($smembers, $result);
     $result1 = $this->redis->hScan($key, $iterator, 'testScanH?llo', 20);
     $this->assertArrayHasKey('testScanHello', $result1);
     $this->assertArrayHasKey('testScanHallo', $result1);
     $this->assertEquals(2, count($result1));
     $this->assertSame(0, $iterator);
 }
示例#2
0
 /**
  * Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.
  *
  * @param string $key
  * @param string $hashKey
  * @param string $value
  *
  * @return bool TRUE if value didn't exist and was added successfully,
  * FALSE if the value was already present and was replaced, FALSE if there was an error.
  * @link http://redis.io/commands/hset
  * @example
  * <pre>
  * $redis->delete('h')
  * $redis->hSet('h', 'key1', 'hello'); // 1, 'key1' => 'hello' in the hash at "h"
  * $redis->hGet('h', 'key1'); // returns "hello"
  * $redis->hSet('h', 'key1', 'plop'); // 0, value was replaced.
  * $redis->hGet('h', 'key1'); // returns "plop"
  * </pre>
  */
 public function hSet($key, $hashKey, $value)
 {
     try {
         return $this->client->hSet($key, $hashKey, $value);
     } catch (Exception $e) {
         return $this->handleException($e, __FUNCTION__, func_get_args());
     }
 }
示例#3
0
 /**
  * Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.
  *
  * @param string $key
  * @param string $hashKey
  * @param string $value
  *
  * @return bool TRUE if value didn't exist and was added successfully,
  * FALSE if the value was already present and was replaced, FALSE if there was an error.
  * @link http://redis.io/commands/hset
  * @example
  * <pre>
  * $redis->delete('h')
  * $redis->hSet('h', 'key1', 'hello'); // 1, 'key1' => 'hello' in the hash at "h"
  * $redis->hGet('h', 'key1'); // returns "hello"
  * $redis->hSet('h', 'key1', 'plop'); // 0, value was replaced.
  * $redis->hGet('h', 'key1'); // returns "plop"
  * </pre>
  */
 public function hSet($key, $hashKey, $value)
 {
     $this->appendToLog('HSET ' . $key . ' ' . $hashKey . ' ' . $value);
     return $this->client->hSet($key, $hashKey, $value);
 }