/** * Adds a string value to the head (left) of the list. Creates the list if the key didn't exist. * If the key exists and is not a list, FALSE is returned. * * @param string $key * @param string $value * * @return int The new length of the list in case of success, FALSE in case of Failure. * @link http://redis.io/commands/lpush * @example * <pre> * $redis->lPush('l', 'v1') // int(1) * $redis->lPush('l', 'v2') // int(2) * var_dump( $redis->lRange('l', 0, -1) ); * //// Output: * // array(2) {2 * // [2]=> string(2) "v2" * // [3]=> string(2) "v1" * // } * </pre> */ public function lPush($key, $value) { try { return $this->client->lPush($key, $value); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
public function testIndexOutOfRangeException() { $this->setExpectedException(IndexOutOfRangeException::class); $this->redis->del('listKey1'); $this->assertEquals(1, $this->redis->lPush('listKey1', 'value1')); $this->assertEquals(2, $this->redis->lPush('listKey1', 'value2')); $this->redis->lset('listKey1', 3, 'value3'); }
/** * Adds a string value to the head (left) of the list. Creates the list if the key didn't exist. * If the key exists and is not a list, FALSE is returned. * * @param string $key * @param string $value * * @return int The new length of the list in case of success, FALSE in case of Failure. * @link http://redis.io/commands/lpush * @example * <pre> * $redis->lPush('l', 'v1') // int(1) * $redis->lPush('l', 'v2') // int(2) * var_dump( $redis->lRange('l', 0, -1) ); * //// Output: * // array(2) {2 * // [2]=> string(2) "v2" * // [3]=> string(2) "v1" * // } * </pre> */ public function lPush($key, $value) { $this->appendToLog('LPUSH ' . $key . ' ' . $value); return $this->client->lPush($key, $value); }