/** * @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; }
/** * Insert value in the list before or after the pivot value. the parameter options * specify the position of the insert (before or after). If the list didn't exist, * or the pivot didn't exist, the value is not inserted. * * @param string $key * @param string $position * @param string $pivot * @param string $value * * @return int The number of the elements in the list, -1 if the pivot didn't exists. * @link http://redis.io/commands/linsert * @example * <pre> * $redis->delete('key1'); * $redis->lInsert('key1', 'after', 'A', 'X'); // 0 * $redis->lPush('key1', 'A'); * $redis->lPush('key1', 'B'); * $redis->lPush('key1', 'C'); * $redis->lInsert('key1', 'before', 'C', 'X'); // 4 * $redis->lRange('key1', 0, -1); // array('A', 'B', 'X', 'C') * $redis->lInsert('key1', 'after', 'C', 'Y'); // 5 * $redis->lRange('key1', 0, -1); // array('A', 'B', 'X', 'C', 'Y') * $redis->lInsert('key1', 'after', 'W', 'value'); // -1 * </pre> */ public function lInsert($key, $position, $pivot, $value) { try { return $this->client->lInsert($key, $position, $pivot, $value); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Insert value in the list before or after the pivot value. the parameter options * specify the position of the insert (before or after). If the list didn't exist, * or the pivot didn't exist, the value is not inserted. * * @param string $key * @param string $position * @param string $pivot * @param string $value * * @return int The number of the elements in the list, -1 if the pivot didn't exists. * @link http://redis.io/commands/linsert * @example * <pre> * $redis->delete('key1'); * $redis->lInsert('key1', 'after', 'A', 'X'); // 0 * $redis->lPush('key1', 'A'); * $redis->lPush('key1', 'B'); * $redis->lPush('key1', 'C'); * $redis->lInsert('key1', 'before', 'C', 'X'); // 4 * $redis->lRange('key1', 0, -1); // array('A', 'B', 'X', 'C') * $redis->lInsert('key1', 'after', 'C', 'Y'); // 5 * $redis->lRange('key1', 0, -1); // array('A', 'B', 'X', 'C', 'Y') * $redis->lInsert('key1', 'after', 'W', 'value'); // -1 * </pre> */ public function lInsert($key, $position, $pivot, $value) { $this->appendToLog('LINSERT ' . $key . ' ' . $position . ' ' . $pivot . ' ' . $value); return $this->client->lInsert($key, $position, $pivot, $value); }