/** * @param $mode * @return array */ protected function doTestSetListFunctions($mode) { $res = array(); $key = 'testMultiSet'; $this->redis->del($key); if ($mode == 'multi') { $this->redis->multi(); } else { $this->redis->pipeline(); } $this->redis->sAdd($key, array('value1', 'value2')); $this->redis->sCard($key); $res['set'] = $this->redis->exec(); $this->assertEquals(array(2, 2), $res['set']); $this->assertEquals(2, $this->redis->sCard($key)); $key = 'testMultiList'; $this->redis->del($key); if ($mode == 'multi') { $this->redis->multi(); } else { $this->redis->pipeline(); } $this->redis->lPush($key, 'value1'); $this->redis->lPush($key, 'value2'); $this->redis->lInsert($key, 'after', 'value1', 'value3'); $this->redis->lLen($key); $this->redis->rPop($key); $res['list'] = $this->redis->exec(); $this->assertEquals(array(1, 2, 3, 3, 'value3'), $res['list']); $this->assertEquals(2, $this->redis->lLen($key)); return $res; }
/** * Returns the cardinality of the set identified by key. * * @param string $key * * @return int the cardinality of the set identified by key, 0 if the set doesn't exist. * @link http://redis.io/commands/scard * @example * <pre> * $redis->sAdd('key1' , 'set1'); * $redis->sAdd('key1' , 'set2'); * $redis->sAdd('key1' , 'set3'); // 'key1' => {'set1', 'set2', 'set3'} * $redis->sCard('key1'); // 3 * $redis->sCard('keyX'); // 0 * </pre> */ public function sCard($key) { try { return $this->client->sCard($key); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }