public function sAdd($key, $value1, $value2 = null, $valueN = null) { $args = func_get_args(); if (count($args) > 2) { $this->signalError('Call to sAdd() with more than 2 arguments.'); // shift off key array_shift($args); return $this->redis->sAdd($key, $args); } return $this->redis->sAdd($key, $value1); }
public function testSScan() { $this->redis->del('testSScan'); $key = 'testSScan'; $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3']; $this->redis->sAdd($key, $members); // 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->sScan($key, $iterator); $this->assertNotEmpty($result); $this->assertNotSame(0, $iterator); $result = array_merge($result, $this->redis->sScan($key, $iterator)); foreach ($members as $member) { $this->assertContains($member, $result); } $this->assertSame(15, count($result)); $this->assertSame(0, $iterator); $smembers = $this->redis->sMembers($key); sort($smembers); sort($result); $this->assertSame($smembers, $result); $result1 = $this->redis->sScan($key, $iterator, 'testScanH?llo', 20); $this->assertContains('testScanHello', $result1); $this->assertContains('testScanHallo', $result1); $this->assertEquals(2, count($result1)); $this->assertSame(0, $iterator); }
/** * Adds one or more values to the set value stored at key. * If one of the values is already in the set, FALSE is returned. * * @param string $key Required key * @param string|array $values * * @return int The number of elements added to the set * @link http://redis.io/commands/sadd * @example * <pre> * $redis->sAdd('k', 'v1'); // int(1) * $redis->sAdd('k', array('v1', 'v2', 'v3')); // int(2) * </pre> */ public function sAdd($key, $values) { try { return $this->client->sAdd($key, $values); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Adds one or more values to the set value stored at key. * If one of the values is already in the set, FALSE is returned. * * @param string $key Required key * @param string|array $values * * @return int The number of elements added to the set * @link http://redis.io/commands/sadd * @example * <pre> * $redis->sAdd('k', 'v1'); // int(1) * $redis->sAdd('k', array('v1', 'v2', 'v3')); // int(2) * </pre> */ public function sAdd($key, $values) { $this->appendToLog('SADD ' . $key . ' ' . $this->keysToString($values)); return $this->client->sAdd($key, $values); }