function testResponseReader_OptionExceptionOnError() { $protocol = new Predis\Protocol\Text\ComposableTextProtocol(); $reader = $protocol->getReader(); $connection = new Predis\Network\ComposableStreamConnection(RC::getConnectionParameters(), $protocol); $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"; $connection->writeBytes("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"); $reader->read($connection); $reader->setHandler(Predis\Protocol\Text\TextProtocol::PREFIX_ERROR, new Predis\Protocol\Text\ResponseErrorSilentHandler()); $connection->writeBytes($rawCmdUnexpected); $errorReply = $reader->read($connection); $this->assertInstanceOf('\\Predis\\ResponseError', $errorReply); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->getMessage()); $reader->setHandler(Predis\Protocol\Text\TextProtocol::PREFIX_ERROR, new Predis\Protocol\Text\ResponseErrorHandler()); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) { $connection->writeBytes($rawCmdUnexpected); $connection->getProtocol()->read($connection); }); }
function testSort() { $unorderedList = RC::pushTailAndReturn($this->redis, 'unordered', array(2, 100, 3, 1, 30, 10)); // without parameters $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->sort('unordered')); // with parameter ASC/DESC $this->assertEquals(array(100, 30, 10, 3, 2, 1), $this->redis->sort('unordered', array('sort' => 'desc'))); // with parameter LIMIT $this->assertEquals(array(1, 2, 3), $this->redis->sort('unordered', array('limit' => array(0, 3)))); $this->assertEquals(array(10, 30), $this->redis->sort('unordered', array('limit' => array(3, 2)))); // with parameter ALPHA $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true))); // with combined parameters $this->assertEquals(array(30, 10, 3, 2), $this->redis->sort('unordered', array('alpha' => false, 'sort' => 'desc', 'limit' => array(1, 4)))); // with parameter ALPHA $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true))); // with parameter STORE $this->assertEquals(count($unorderedList), $this->redis->sort('unordered', array('store' => 'ordered'))); $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->lrange('ordered', 0, -1)); // with parameter GET $this->redis->rpush('uids', 1003); $this->redis->rpush('uids', 1001); $this->redis->rpush('uids', 1002); $this->redis->rpush('uids', 1000); $sortget = array('uid:1000' => 'foo', 'uid:1001' => 'bar', 'uid:1002' => 'hoge', 'uid:1003' => 'piyo'); $this->redis->mset($sortget); $this->assertEquals(array_values($sortget), $this->redis->sort('uids', array('get' => 'uid:*'))); // wrong type RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, p_anon("\$test", "\n \$test->redis->set('foo', 'bar');\n \$test->redis->sort('foo');\n ")); }
function testSort() { $unorderedList = RC::pushTailAndReturn($this->redis, 'unordered', array(2, 100, 3, 1, 30, 10)); // without parameters $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->sort('unordered')); // with parameter ASC/DESC $this->assertEquals(array(100, 30, 10, 3, 2, 1), $this->redis->sort('unordered', array('sort' => 'desc'))); // with parameter LIMIT $this->assertEquals(array(1, 2, 3), $this->redis->sort('unordered', array('limit' => array(0, 3)))); $this->assertEquals(array(10, 30), $this->redis->sort('unordered', array('limit' => array(3, 2)))); // with parameter ALPHA $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true))); // with combined parameters $this->assertEquals(array(30, 10, 3, 2), $this->redis->sort('unordered', array('alpha' => false, 'sort' => 'desc', 'limit' => array(1, 4)))); // with parameter ALPHA $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true))); // with parameter STORE $this->assertEquals(count($unorderedList), $this->redis->sort('unordered', array('store' => 'ordered'))); $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->listRange('ordered', 0, -1)); // wront type RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function ($test) { $test->redis->set('foo', 'bar'); $test->redis->sort('foo'); }); }
function testResponseReader_OptionExceptionOnError() { $connection = new \Predis\TcpConnection(RC::getConnectionParameters()); $responseReader = $connection->getResponseReader(); $connection->rawCommand("SET key 5\r\nvalue\r\n"); $rawCmdUnexpected = "LPUSH key 5\r\nvalue\r\n"; $responseReader->setHandler(\Predis\Protocol::PREFIX_ERROR, new \Predis\ResponseErrorSilentHandler()); $errorReply = $connection->rawCommand($rawCmdUnexpected); $this->assertType('\\Predis\\ResponseError', $errorReply); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message); $responseReader->setHandler(\Predis\Protocol::PREFIX_ERROR, new \Predis\ResponseErrorHandler()); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) { $connection->rawCommand($rawCmdUnexpected); }); }
function testResponseReader_OptionExceptionOnError() { $connection = new \Predis\Connection(RC::getConnectionParameters()); $responseReader = $connection->getResponseReader(); $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"); $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"; $responseReader->setOption('throw_on_error', false); $errorReply = $connection->rawCommand($rawCmdUnexpected); $this->assertInstanceOf('\\Predis\\ResponseError', $errorReply); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message); $responseReader->setOption('throw_on_error', true); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) { $connection->rawCommand($rawCmdUnexpected); }); }