mirror of
https://github.com/predis/predis.git
synced 2026-08-20 14:13:19 +00:00
Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f97312d683 | |||
| 17f83a5605 | |||
| b1254a1375 | |||
| 572fb292f1 | |||
| 6301ae1402 | |||
| 7644d7fbeb | |||
| 72e117673e | |||
| 6b7f47e087 | |||
| 434b9dd0f7 | |||
| e5f010deb8 | |||
| 785d0f429f | |||
| 736a102aba | |||
| 6b2697a133 | |||
| b6b732ec51 | |||
| 1bc891bed1 | |||
| 1e47fb88f3 | |||
| b882344840 | |||
| e5e8a19c7a | |||
| ffcbc4fdb1 | |||
| e398ff977e | |||
| 18b44fae53 | |||
| e800f1904b | |||
| c73d0b375b | |||
| 9f1f07083a | |||
| e1f8942569 | |||
| 235d311cb1 | |||
| c03ab9480e | |||
| 6f46fa1f2d | |||
| 798e2b18dc | |||
| aaa16c8276 | |||
| e700061cc0 | |||
| e67cfe27b3 | |||
| e6e638b79e | |||
| 96132ee50c | |||
| f36d7a1d56 | |||
| ca6ff4f734 | |||
| bc0e29c1d2 | |||
| 627c3a1724 | |||
| 06d974c0bc | |||
| 6b6edbe6c2 | |||
| f76d616d57 | |||
| c41bb2c314 | |||
| d4fb7d9143 | |||
| ca422b0300 | |||
| 79372cb99b | |||
| 6a2e4d0396 | |||
| 78814a473c | |||
| 0d7fe31110 | |||
| 118af2809c | |||
| 8dcd10dbbc | |||
| 3a6907241b | |||
| eae29bc3da | |||
| 727feb3f27 | |||
| 3924235501 | |||
| dc704c8cc4 | |||
| 8d6f65d3dd | |||
| 40dfabb139 | |||
| a605190354 | |||
| b5ce81a030 | |||
| a9e1d6b86b | |||
| 923d998f35 | |||
| eae8fb8971 | |||
| 4fc5ee65fd | |||
| 007ddaecfa | |||
| 455e56927a | |||
| 4b1302a93a | |||
| d46b0e0785 | |||
| cf522ff2b4 | |||
| db92c7a9b8 | |||
| 30926def60 | |||
| 7465daa0eb | |||
| 2c761d6c95 | |||
| 1e32f8aaa8 | |||
| 2a25b0e3f3 | |||
| 5a6a48fa17 | |||
| 64951b1799 |
@@ -1,3 +1,55 @@
|
||||
v0.6.6 (2011-04-01)
|
||||
* Switched to Redis 2.2 as the default server profile (there are no changes
|
||||
that would break compatibility with previous releases). Long command names
|
||||
are no more supported by default but if you need them you can still require
|
||||
Predis_Compatibility.php to avoid breaking compatibility.
|
||||
|
||||
* Added a VERSION constant to Predis\Client.
|
||||
|
||||
* Some performance improvements for multibulk replies (parsing them is about
|
||||
16% faster than the previous version). A few core classes have been heavily
|
||||
optimized to reduce overhead when creating new instances.
|
||||
|
||||
* Predis now uses by default a new protocol reader, more lightweight and
|
||||
faster than the default handler-based one. Users can revert to the old
|
||||
protocol reader with the 'reader' client option set to 'composable'.
|
||||
This client option can also accept custom reader classes implementing the
|
||||
new Predis\IResponseReader interface.
|
||||
|
||||
* Added support for connecting to Redis using UNIX domain sockets (ISSUE #25).
|
||||
|
||||
* The "read_write_timeout" connection parameter can now be set to 0 or false
|
||||
to disable read and write timeouts on connections. The old behaviour of -1
|
||||
is still intact.
|
||||
|
||||
* ZUNIONSTORE and ZINTERSTORE can accept an array to specify a list of the
|
||||
source keys to be used to populate the destination key.
|
||||
|
||||
* MGET, SINTER, SUNION and SDIFF can accept an array to specify the list of
|
||||
keys. SINTERSTORE, SUNIONSTORE and SDIFFSTORE can also accept an array to
|
||||
specify the list of source keys.
|
||||
|
||||
* SUBSCRIBE and PSUBSCRIBE can accept a list of channels for subscription.
|
||||
|
||||
* FIX: some client-side clean-ups for MULTI/EXEC were handled incorrectly in
|
||||
a couple of corner cases. See also ISSUE #27.
|
||||
|
||||
v0.6.5 (2011-02-12)
|
||||
* FIX: due to an untested internal change introduced in v0.6.4, a wrong
|
||||
handling of bulk reads of zero-length values was producing protocol
|
||||
desynchronization errors (ISSUE #20).
|
||||
|
||||
v0.6.4 (2011-02-12)
|
||||
* Various performance improvements (15% ~ 25%) especially when dealing with
|
||||
long multibulk replies or when using clustered connections.
|
||||
|
||||
* Added the "on_retry" option to Predis\MultiExecBlock that can be used to
|
||||
specify an external callback (or any callable object) that gets invoked
|
||||
whenever a transaction is aborted by the server.
|
||||
|
||||
* Added inline (p)subscribtion via options when initializing an instance of
|
||||
Predis\PubSubContext.
|
||||
|
||||
v0.6.3 (2011-01-01)
|
||||
* New commands available in the Redis v2.2 profile (dev):
|
||||
- Strings: SETRANGE, GETRANGE, SETBIT, GETBIT
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009-2010 Daniele Alessandri
|
||||
Copyright (c) 2009-2011 Daniele Alessandri
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
+2
-1
@@ -17,11 +17,12 @@ to be implemented soon in Predis.
|
||||
|
||||
## Main features ##
|
||||
|
||||
- Full support for Redis 2.0. Different versions of Redis are supported via server profiles.
|
||||
- Full support for Redis 2.0 and 2.2. Different versions of Redis are supported via server profiles.
|
||||
- Client-side sharding (support for consistent hashing and custom distribution strategies).
|
||||
- Command pipelining on single and multiple connections (transparent).
|
||||
- Abstraction for Redis transactions (>= 2.0) with support for CAS operations (>= 2.2).
|
||||
- Lazy connections (connections to Redis instances are only established just in time).
|
||||
- Ability to connect to Redis using TCP/IP or UNIX domain sockets.
|
||||
- Flexible system to define and register your own set of commands to a client instance.
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require_once 'SharedConfigurations.php';
|
||||
|
||||
// Developers can customize the distribution strategy used by the client
|
||||
// to distribute keys among a cluster of servers simply by creating a class
|
||||
// that implements the Predis\Distribution\IDistributionAlgorithm interface.
|
||||
// that implements the Predis\Distribution\IDistributionStrategy interface.
|
||||
|
||||
class NaiveDistributionStrategy
|
||||
implements Predis\Distribution\IDistributionStrategy {
|
||||
|
||||
@@ -5,7 +5,7 @@ require_once 'SharedConfigurations.php';
|
||||
// events published on certain channels (PUBSUB).
|
||||
|
||||
// Create a client and disable r/w timeout on the socket
|
||||
$redis = new Predis\Client($single_server + array('read_write_timeout' => -1));
|
||||
$redis = new Predis\Client($single_server + array('read_write_timeout' => 0));
|
||||
|
||||
// Initialize a new pubsub context
|
||||
$pubsub = $redis->pubSubContext();
|
||||
|
||||
+848
-406
File diff suppressed because it is too large
Load Diff
+738
-500
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="test/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Predis Test Suite">
|
||||
<directory>test/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">lib/Predis/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
@@ -1,19 +1,14 @@
|
||||
<?php
|
||||
define('I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE', false);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PredisShared.php';
|
||||
require_once '../lib/Predis_Compatibility.php';
|
||||
|
||||
class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
public $redis;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp() {
|
||||
$this->redis = RC::getConnection();
|
||||
$this->redis->flushDatabase();
|
||||
$this->redis->flushdb();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown() {
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(Exception $exception) {
|
||||
@@ -89,7 +84,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
function testCommand_InlineWithNoArguments() {
|
||||
$cmd = new \Predis\Compatibility\v1_0\Commands\Ping();
|
||||
|
||||
$this->assertType('\Predis\InlineCommand', $cmd);
|
||||
$this->assertInstanceOf('\Predis\InlineCommand', $cmd);
|
||||
$this->assertEquals('PING', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertFalse($cmd->canBeHashed());
|
||||
@@ -101,7 +96,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$cmd = new \Predis\Compatibility\v1_0\Commands\Get();
|
||||
$cmd->setArgumentsArray(array('key'));
|
||||
|
||||
$this->assertType('\Predis\InlineCommand', $cmd);
|
||||
$this->assertInstanceOf('\Predis\InlineCommand', $cmd);
|
||||
$this->assertEquals('GET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertTrue($cmd->canBeHashed());
|
||||
@@ -113,7 +108,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$cmd = new \Predis\Compatibility\v1_0\Commands\Set();
|
||||
$cmd->setArgumentsArray(array('key', 'value'));
|
||||
|
||||
$this->assertType('\Predis\BulkCommand', $cmd);
|
||||
$this->assertInstanceOf('\Predis\BulkCommand', $cmd);
|
||||
$this->assertEquals('SET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertTrue($cmd->canBeHashed());
|
||||
@@ -125,7 +120,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$cmd = new \Predis\Commands\SetMultiple();
|
||||
$cmd->setArgumentsArray(array('key1', 'value1', 'key2', 'value2'));
|
||||
|
||||
$this->assertType('\Predis\MultiBulkCommand', $cmd);
|
||||
$this->assertInstanceOf('\Predis\MultiBulkCommand', $cmd);
|
||||
$this->assertEquals('MSET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertFalse($cmd->canBeHashed());
|
||||
@@ -155,11 +150,11 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
/* RedisServerProfile and derivates */
|
||||
|
||||
function testRedisServerProfile_GetSpecificVersions() {
|
||||
$this->assertType('\Predis\RedisServer_v1_0', \Predis\RedisServerProfile::get('1.0'));
|
||||
$this->assertType('\Predis\RedisServer_v1_2', \Predis\RedisServerProfile::get('1.2'));
|
||||
$this->assertType('\Predis\RedisServer_v2_0', \Predis\RedisServerProfile::get('2.0'));
|
||||
$this->assertType('\Predis\RedisServer_vNext', \Predis\RedisServerProfile::get('dev'));
|
||||
$this->assertType('\Predis\RedisServerProfile', \Predis\RedisServerProfile::get('default'));
|
||||
$this->assertInstanceOf('\Predis\RedisServer_v1_0', \Predis\RedisServerProfile::get('1.0'));
|
||||
$this->assertInstanceOf('\Predis\RedisServer_v1_2', \Predis\RedisServerProfile::get('1.2'));
|
||||
$this->assertInstanceOf('\Predis\RedisServer_v2_0', \Predis\RedisServerProfile::get('2.0'));
|
||||
$this->assertInstanceOf('\Predis\RedisServer_vNext', \Predis\RedisServerProfile::get('dev'));
|
||||
$this->assertInstanceOf('\Predis\RedisServerProfile', \Predis\RedisServerProfile::get('default'));
|
||||
$this->assertEquals(\Predis\RedisServerProfile::get('default'), \Predis\RedisServerProfile::getDefault());
|
||||
}
|
||||
|
||||
@@ -181,12 +176,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$profile = \Predis\RedisServerProfile::get('1.0');
|
||||
|
||||
$cmdNoArgs = $profile->createCommand('info');
|
||||
$this->assertType('\Predis\Compatibility\v1_0\Commands\Info', $cmdNoArgs);
|
||||
$this->assertInstanceOf('\Predis\Compatibility\v1_0\Commands\Info', $cmdNoArgs);
|
||||
$this->assertNull($cmdNoArgs->getArgument());
|
||||
|
||||
$args = array('key1', 'key2');
|
||||
$cmdWithArgs = $profile->createCommand('mget', $args);
|
||||
$this->assertType('\Predis\Compatibility\v1_0\Commands\GetMultiple', $cmdWithArgs);
|
||||
$this->assertInstanceOf('\Predis\Compatibility\v1_0\Commands\GetMultiple', $cmdWithArgs);
|
||||
$this->assertEquals($args[0], $cmdWithArgs->getArgument()); // TODO: why?
|
||||
$this->assertEquals($args[0], $cmdWithArgs->getArgument(0));
|
||||
$this->assertEquals($args[1], $cmdWithArgs->getArgument(1));
|
||||
@@ -208,7 +203,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertFalse($profile->supportsCommand($cmdId));
|
||||
$profile->registerCommand(new $cmdClass(), $cmdId);
|
||||
$this->assertTrue($profile->supportsCommand($cmdId));
|
||||
$this->assertType($cmdClass, $profile->createCommand($cmdId));
|
||||
$this->assertInstanceOf($cmdClass, $profile->createCommand($cmdId));
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +211,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testResponseQueued() {
|
||||
$response = new \Predis\ResponseQueued();
|
||||
$this->assertTrue($response->skipParse);
|
||||
$this->assertTrue($response->queued);
|
||||
$this->assertEquals(\Predis\Protocol::QUEUED, (string)$response);
|
||||
}
|
||||
@@ -227,6 +223,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$errorMessage = 'ERROR MESSAGE';
|
||||
$response = new \Predis\ResponseError($errorMessage);
|
||||
|
||||
$this->assertTrue($response->skipParse);
|
||||
$this->assertTrue($response->error);
|
||||
$this->assertEquals($errorMessage, $response->message);
|
||||
$this->assertEquals($errorMessage, (string)$response);
|
||||
@@ -280,7 +277,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$connection = new \Predis\Connection(RC::getConnectionParameters());
|
||||
|
||||
$this->assertFalse($connection->isConnected());
|
||||
$this->assertType('resource', $connection->getSocket());
|
||||
$this->assertInternalType('resource', $connection->getSocket());
|
||||
$this->assertTrue($connection->isConnected());
|
||||
}
|
||||
|
||||
@@ -339,19 +336,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testResponseReader_OptionIterableMultiBulkReplies() {
|
||||
$connection = new \Predis\Connection(RC::getConnectionParameters());
|
||||
$responseReader = $connection->getResponseReader();
|
||||
|
||||
$responseReader->setHandler(
|
||||
\Predis\Protocol::PREFIX_MULTI_BULK,
|
||||
new \Predis\ResponseMultiBulkHandler()
|
||||
);
|
||||
$this->assertType('array', $connection->rawCommand("KEYS *\r\n"));
|
||||
$connection->getResponseReader()->setOption('iterable_multibulk', false);
|
||||
$this->assertInternalType('array', $connection->rawCommand("KEYS *\r\n"));
|
||||
|
||||
$responseReader->setHandler(
|
||||
\Predis\Protocol::PREFIX_MULTI_BULK,
|
||||
new \Predis\ResponseMultiBulkStreamHandler()
|
||||
);
|
||||
$this->assertType('\Iterator', $connection->rawCommand("KEYS *\r\n"));
|
||||
$connection->getResponseReader()->setOption('iterable_multibulk', true);
|
||||
$this->assertInstanceOf('\Iterator', $connection->rawCommand("KEYS *\r\n"));
|
||||
}
|
||||
|
||||
function testResponseReader_OptionExceptionOnError() {
|
||||
@@ -360,18 +350,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$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->setHandler(
|
||||
\Predis\Protocol::PREFIX_ERROR,
|
||||
new \Predis\ResponseErrorSilentHandler()
|
||||
);
|
||||
$responseReader->setOption('throw_on_error', false);
|
||||
$errorReply = $connection->rawCommand($rawCmdUnexpected);
|
||||
$this->assertType('\Predis\ResponseError', $errorReply);
|
||||
$this->assertInstanceOf('\Predis\ResponseError', $errorReply);
|
||||
$this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
|
||||
|
||||
$responseReader->setHandler(
|
||||
\Predis\Protocol::PREFIX_ERROR,
|
||||
new \Predis\ResponseErrorHandler()
|
||||
);
|
||||
$responseReader->setOption('throw_on_error', true);
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function()
|
||||
use ($connection, $rawCmdUnexpected) {
|
||||
|
||||
@@ -379,6 +363,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testResponseReader_EmptyBulkResponse() {
|
||||
$this->assertTrue($this->redis->set('foo', ''));
|
||||
$this->assertEquals('', $this->redis->get('foo'));
|
||||
$this->assertEquals('', $this->redis->get('foo'));
|
||||
}
|
||||
|
||||
|
||||
/* Client + CommandPipeline */
|
||||
|
||||
@@ -388,18 +378,18 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$pipe = $client->pipeline();
|
||||
|
||||
$this->assertType('\Predis\CommandPipeline', $pipe);
|
||||
$this->assertType('\Predis\CommandPipeline', $pipe->set('foo', 'bar'));
|
||||
$this->assertType('\Predis\CommandPipeline', $pipe->set('hoge', 'piyo'));
|
||||
$this->assertType('\Predis\CommandPipeline', $pipe->mset(array(
|
||||
$this->assertInstanceOf('\Predis\CommandPipeline', $pipe);
|
||||
$this->assertInstanceOf('\Predis\CommandPipeline', $pipe->set('foo', 'bar'));
|
||||
$this->assertInstanceOf('\Predis\CommandPipeline', $pipe->set('hoge', 'piyo'));
|
||||
$this->assertInstanceOf('\Predis\CommandPipeline', $pipe->mset(array(
|
||||
'foofoo' => 'barbar', 'hogehoge' => 'piyopiyo'
|
||||
)));
|
||||
$this->assertType('\Predis\CommandPipeline', $pipe->mget(array(
|
||||
$this->assertInstanceOf('\Predis\CommandPipeline', $pipe->mget(array(
|
||||
'foo', 'hoge', 'foofoo', 'hogehoge'
|
||||
)));
|
||||
|
||||
$replies = $pipe->execute();
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(4, count($replies));
|
||||
$this->assertEquals(4, count($replies[3]));
|
||||
$this->assertEquals('barbar', $replies[3][2]);
|
||||
@@ -410,7 +400,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->pipeline()->ping()->set('foo', 'bar')->get('foo')->execute();
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals('bar', $replies[2]);
|
||||
}
|
||||
|
||||
@@ -418,13 +408,13 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->pipeline(function($pipe) {
|
||||
$replies = $client->pipeline(function($pipe) {
|
||||
$pipe->ping();
|
||||
$pipe->set('foo', 'bar');
|
||||
$pipe->get('foo');
|
||||
});
|
||||
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals('bar', $replies[2]);
|
||||
}
|
||||
|
||||
@@ -433,7 +423,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client->flushdb();
|
||||
|
||||
RC::testForClientException($this, 'TEST', function() use($client) {
|
||||
$client->pipeline(function($pipe) {
|
||||
$client->pipeline(function($pipe) {
|
||||
$pipe->ping();
|
||||
$pipe->set('foo', 'bar');
|
||||
throw new \Predis\ClientException("TEST");
|
||||
@@ -445,16 +435,16 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
function testCommandPipeline_ServerExceptionInCallableBlock() {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
$client->getResponseReader()->setHandler('-', new \Predis\ResponseErrorSilentHandler());
|
||||
$client->getResponseReader()->setOption('throw_on_error', false);
|
||||
|
||||
$replies = $client->pipeline(function($pipe) {
|
||||
$replies = $client->pipeline(function($pipe) {
|
||||
$pipe->set('foo', 'bar');
|
||||
$pipe->lpush('foo', 'piyo'); // LIST operation on STRING type returns an ERROR
|
||||
$pipe->set('hoge', 'piyo');
|
||||
});
|
||||
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertType('\Predis\ResponseError', $replies[1]);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertInstanceOf('\Predis\ResponseError', $replies[1]);
|
||||
$this->assertTrue($client->exists('foo'));
|
||||
$this->assertTrue($client->exists('hoge'));
|
||||
}
|
||||
@@ -469,7 +459,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$pipe->ping()->mget(array('foo', 'hoge'));
|
||||
$replies = $pipe->execute();
|
||||
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(4, count($replies));
|
||||
$this->assertEquals('bar', $replies[3][0]);
|
||||
$this->assertEquals('piyo', $replies[3][1]);
|
||||
@@ -484,18 +474,18 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$multi = $client->multiExec();
|
||||
|
||||
$this->assertType('\Predis\MultiExecBlock', $multi);
|
||||
$this->assertType('\Predis\MultiExecBlock', $multi->set('foo', 'bar'));
|
||||
$this->assertType('\Predis\MultiExecBlock', $multi->set('hoge', 'piyo'));
|
||||
$this->assertType('\Predis\MultiExecBlock', $multi->mset(array(
|
||||
$this->assertInstanceOf('\Predis\MultiExecBlock', $multi);
|
||||
$this->assertInstanceOf('\Predis\MultiExecBlock', $multi->set('foo', 'bar'));
|
||||
$this->assertInstanceOf('\Predis\MultiExecBlock', $multi->set('hoge', 'piyo'));
|
||||
$this->assertInstanceOf('\Predis\MultiExecBlock', $multi->mset(array(
|
||||
'foofoo' => 'barbar', 'hogehoge' => 'piyopiyo'
|
||||
)));
|
||||
$this->assertType('\Predis\MultiExecBlock', $multi->mget(array(
|
||||
$this->assertInstanceOf('\Predis\MultiExecBlock', $multi->mget(array(
|
||||
'foo', 'hoge', 'foofoo', 'hogehoge'
|
||||
)));
|
||||
|
||||
$replies = $multi->execute();
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(4, count($replies));
|
||||
$this->assertEquals(4, count($replies[3]));
|
||||
$this->assertEquals('barbar', $replies[3][2]);
|
||||
@@ -506,7 +496,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->multiExec()->ping()->set('foo', 'bar')->get('foo')->execute();
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals('bar', $replies[2]);
|
||||
}
|
||||
|
||||
@@ -514,13 +504,13 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$multi->ping();
|
||||
$multi->set('foo', 'bar');
|
||||
$multi->get('foo');
|
||||
});
|
||||
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals('bar', $replies[2]);
|
||||
}
|
||||
|
||||
@@ -555,7 +545,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client->flushdb();
|
||||
|
||||
RC::testForClientException($this, 'TEST', function() use($client) {
|
||||
$client->multiExec(function($multi) {
|
||||
$client->multiExec(function($multi) {
|
||||
$multi->ping();
|
||||
$multi->set('foo', 'bar');
|
||||
throw new \Predis\ClientException("TEST");
|
||||
@@ -567,16 +557,16 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
function testMultiExecBlock_ServerExceptionInCallableBlock() {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
$client->getResponseReader()->setHandler('-', new \Predis\ResponseErrorSilentHandler());
|
||||
$client->getResponseReader()->setOption('throw_on_error', false);
|
||||
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$multi->set('foo', 'bar');
|
||||
$multi->lpush('foo', 'piyo'); // LIST operation on STRING type returns an ERROR
|
||||
$multi->set('hoge', 'piyo');
|
||||
});
|
||||
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertType('\Predis\ResponseError', $replies[1]);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertInstanceOf('\Predis\ResponseError', $replies[1]);
|
||||
$this->assertTrue($client->exists('foo'));
|
||||
$this->assertTrue($client->exists('hoge'));
|
||||
}
|
||||
@@ -585,7 +575,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$multi->set('foo', 'bar');
|
||||
$multi->discard();
|
||||
$multi->set('hoge', 'piyo');
|
||||
@@ -600,7 +590,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$client = RC::getConnection();
|
||||
$client->flushdb();
|
||||
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$replies = $client->multiExec(function($multi) {
|
||||
$multi->discard();
|
||||
});
|
||||
|
||||
@@ -640,7 +630,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$tx->set('foobar', $foo);
|
||||
$tx->mget('foo', 'foobar');
|
||||
});
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(array(true, array('bar', 'bar')), $replies);
|
||||
|
||||
$tx = $client->multiExec($options);
|
||||
@@ -650,7 +640,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
->set('foobar', $foo)
|
||||
->mget('foo', 'foobar')
|
||||
->execute();
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(array(true, array('bar', 'bar')), $replies);
|
||||
}
|
||||
|
||||
@@ -726,7 +716,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$tx->discard();
|
||||
$tx->mget('foo', 'foobar');
|
||||
});
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(array(array('bar', null)), $replies);
|
||||
|
||||
$hijack = true;
|
||||
@@ -746,7 +736,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
$tx->mget('foo', 'foobar');
|
||||
});
|
||||
$this->assertType('array', $replies);
|
||||
$this->assertInternalType('array', $replies);
|
||||
$this->assertEquals(array(array('hijacked!', null)), $replies);
|
||||
}
|
||||
}
|
||||
+23
-11
@@ -1,12 +1,23 @@
|
||||
<?php
|
||||
require_once '../lib/Predis.php';
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
define('I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE', false);
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
if (I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE !== true) {
|
||||
exit('Please set the I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE constant to TRUE if you want to proceed.');
|
||||
exit(
|
||||
"Please set the I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE " .
|
||||
"constant to TRUE in PredisShared.php if you want to proceed.\n"
|
||||
);
|
||||
}
|
||||
|
||||
Predis\RedisServerProfile::registerProfile('\Predis\RedisServer_v1_2', '1.2');
|
||||
Predis\RedisServerProfile::registerProfile('\Predis\RedisServer_v2_0', '2.0');
|
||||
Predis\RedisServerProfile::registerProfile('\Predis\RedisServer_v2_2', '2.2');
|
||||
|
||||
if (!function_exists('array_union')) {
|
||||
function array_union(Array $a, Array $b) {
|
||||
function array_union(Array $a, Array $b) {
|
||||
return array_merge($a, array_diff($b, $a));
|
||||
}
|
||||
}
|
||||
@@ -31,16 +42,16 @@ class RC {
|
||||
|
||||
private static $_connection;
|
||||
|
||||
public static function getConnectionArguments() {
|
||||
public static function getConnectionArguments() {
|
||||
return array('host' => RC::SERVER_HOST, 'port' => RC::SERVER_PORT);
|
||||
}
|
||||
|
||||
public static function getConnectionParameters() {
|
||||
public static function getConnectionParameters() {
|
||||
return new Predis\ConnectionParameters(array('host' => RC::SERVER_HOST, 'port' => RC::SERVER_PORT));
|
||||
}
|
||||
|
||||
private static function createConnection() {
|
||||
$serverProfile = Predis\RedisServerProfile::get('dev');
|
||||
$serverProfile = Predis\RedisServerProfile::get('2.2');
|
||||
$connection = new Predis\Client(RC::getConnectionArguments(), $serverProfile);
|
||||
$connection->connect();
|
||||
$connection->select(RC::DEFAULT_DATABASE);
|
||||
@@ -69,8 +80,9 @@ class RC {
|
||||
// in a separate process to properly test BLPOP/BRPOP
|
||||
$redisUri = sprintf('redis://%s:%d/?database=%d', RC::SERVER_HOST, RC::SERVER_PORT, RC::DEFAULT_DATABASE);
|
||||
$handle = popen('php', 'w');
|
||||
$dir = __DIR__;
|
||||
fwrite($handle, "<?php
|
||||
require '../lib/Predis.php';
|
||||
require '{$dir}/../lib/Predis.php';
|
||||
\$redis = Predis\Client::create('$redisUri');
|
||||
\$redis->rpush('{$op}1', 'a');
|
||||
\$redis->rpush('{$op}2', 'b');
|
||||
@@ -121,7 +133,7 @@ class RC {
|
||||
catch (Predis\ServerException $exception) {
|
||||
$thrownException = $exception;
|
||||
}
|
||||
$testcaseInstance->assertType('Predis\ServerException', $thrownException);
|
||||
$testcaseInstance->assertInstanceOf('Predis\ServerException', $thrownException);
|
||||
if (isset($expectedMessage)) {
|
||||
$testcaseInstance->assertEquals($expectedMessage, $thrownException->getMessage());
|
||||
}
|
||||
@@ -135,7 +147,7 @@ class RC {
|
||||
catch (Predis\ClientException $exception) {
|
||||
$thrownException = $exception;
|
||||
}
|
||||
$testcaseInstance->assertType('Predis\ClientException', $thrownException);
|
||||
$testcaseInstance->assertInstanceOf('Predis\ClientException', $thrownException);
|
||||
if (isset($expectedMessage)) {
|
||||
$testcaseInstance->assertEquals($expectedMessage, $thrownException->getMessage());
|
||||
}
|
||||
@@ -149,7 +161,7 @@ class RC {
|
||||
catch (Predis\CommunicationException $exception) {
|
||||
$thrownException = $exception;
|
||||
}
|
||||
$testcaseInstance->assertType('Predis\CommunicationException', $thrownException);
|
||||
$testcaseInstance->assertInstanceOf('Predis\CommunicationException', $thrownException);
|
||||
if (isset($expectedMessage)) {
|
||||
$testcaseInstance->assertEquals($expectedMessage, $thrownException->getMessage());
|
||||
}
|
||||
@@ -163,7 +175,7 @@ class RC {
|
||||
catch (Predis\AbortedMultiExec $exception) {
|
||||
$thrownException = $exception;
|
||||
}
|
||||
$testcaseInstance->assertType('Predis\AbortedMultiExec', $thrownException);
|
||||
$testcaseInstance->assertInstanceOf('Predis\AbortedMultiExec', $thrownException);
|
||||
}
|
||||
|
||||
public static function pushTailAndReturn(Predis\Client $client, $keyName, Array $values, $wipeOut = 0) {
|
||||
|
||||
+54
-15
@@ -1,10 +1,6 @@
|
||||
<?php
|
||||
define('I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE', false);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PredisShared.php';
|
||||
|
||||
class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
class RedisCommandsTestSuite extends PHPUnit_Framework_TestCase {
|
||||
public $redis;
|
||||
|
||||
// TODO: instead of an boolean assertion against the return value
|
||||
@@ -14,12 +10,12 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
// should be provided.
|
||||
// TODO: missing test with float values for a few commands
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp() {
|
||||
$this->redis = RC::getConnection();
|
||||
$this->redis->flushdb();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown() {
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(Exception $exception) {
|
||||
@@ -51,9 +47,9 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
// respective Predis\Command::parseResponse methods. If you need that
|
||||
// kind of behaviour, you should use an instance of Predis\MultiExecBlock.
|
||||
$this->assertTrue($this->redis->multi());
|
||||
$this->assertType('Predis\ResponseQueued', $this->redis->ping());
|
||||
$this->assertType('Predis\ResponseQueued', $this->redis->echo('hello'));
|
||||
$this->assertType('Predis\ResponseQueued', $this->redis->echo('redis'));
|
||||
$this->assertInstanceOf('Predis\ResponseQueued', $this->redis->ping());
|
||||
$this->assertInstanceOf('Predis\ResponseQueued', $this->redis->echo('hello'));
|
||||
$this->assertInstanceOf('Predis\ResponseQueued', $this->redis->echo('redis'));
|
||||
$this->assertEquals(array('PONG', 'hello', 'redis'), $this->redis->exec());
|
||||
|
||||
$this->assertTrue($this->redis->multi());
|
||||
@@ -67,8 +63,8 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testDiscard() {
|
||||
$this->assertTrue($this->redis->multi());
|
||||
$this->assertType('Predis\ResponseQueued', $this->redis->set('foo', 'bar'));
|
||||
$this->assertType('Predis\ResponseQueued', $this->redis->set('hoge', 'piyo'));
|
||||
$this->assertInstanceOf('Predis\ResponseQueued', $this->redis->set('foo', 'bar'));
|
||||
$this->assertInstanceOf('Predis\ResponseQueued', $this->redis->set('hoge', 'piyo'));
|
||||
$this->assertEquals(true, $this->redis->discard());
|
||||
|
||||
// should throw an exception when trying to EXEC after a DISCARD
|
||||
@@ -89,8 +85,11 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testGet() {
|
||||
$this->redis->set('foo', 'bar');
|
||||
|
||||
$this->assertEquals('bar', $this->redis->get('foo'));
|
||||
|
||||
$this->assertTrue($this->redis->set('foo', ''));
|
||||
$this->assertEquals('', $this->redis->get('foo'));
|
||||
|
||||
$this->assertNull($this->redis->get('fooDoesNotExist'));
|
||||
|
||||
// should throw an exception when trying to do a GET on non-string types
|
||||
@@ -251,7 +250,7 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('bar', $this->redis->substr('var', 3, 5));
|
||||
$this->assertEquals('bar', $this->redis->substr('var', -3, -1));
|
||||
|
||||
$this->assertNull($this->redis->substr('var', 5, 0));
|
||||
$this->assertEquals($this->redis->substr('var', 5, 0), '');
|
||||
|
||||
$this->redis->set('numeric', 123456789);
|
||||
$this->assertEquals(12345, $this->redis->substr('numeric', 0, 4));
|
||||
@@ -1013,6 +1012,9 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->redis->set('foo', 'bar');
|
||||
$this->assertEquals(count($setA), $this->redis->sinterstore('foo', 'setA'));
|
||||
|
||||
// accepts an array for the list of source keys
|
||||
$this->assertEquals(4, $this->redis->sinterstore('setC', array('setA', 'setB')));
|
||||
|
||||
// wrong type
|
||||
$this->redis->set('foo', 'bar');
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
|
||||
@@ -1076,6 +1078,9 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->redis->set('foo', 'bar');
|
||||
$this->assertEquals(count($setA), $this->redis->sunionstore('foo', 'setA'));
|
||||
|
||||
// accepts an array for the list of source keys
|
||||
$this->assertEquals(9, $this->redis->sunionstore('setC', array('setA', 'setB')));
|
||||
|
||||
// wrong type
|
||||
$this->redis->set('foo', 'bar');
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
|
||||
@@ -1504,6 +1509,23 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
// using an array to pass the list of source keys
|
||||
$sourceKeys = array('zseta', 'zsetb');
|
||||
|
||||
$this->assertEquals(4, $this->redis->zunionstore('zsetc', $sourceKeys));
|
||||
$this->assertEquals(
|
||||
array(array('a', 1), array('b', 3), array('d', 3), array('c', 5)),
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
// using an array to pass the list of source keys + options array
|
||||
$options = array('weights' => array(2, 3));
|
||||
$this->assertEquals(4, $this->redis->zunionstore('zsetc', $sourceKeys, $options));
|
||||
$this->assertEquals(
|
||||
array(array('a', 2), array('b', 7), array('d', 9), array('c', 12)),
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
|
||||
$test->redis->set('zsetFake', 'fake');
|
||||
$test->redis->zunionstore('zsetc', 2, 'zseta', 'zsetFake');
|
||||
@@ -1549,6 +1571,23 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
// using an array to pass the list of source keys
|
||||
$sourceKeys = array('zseta', 'zsetb');
|
||||
|
||||
$this->assertEquals(2, $this->redis->zinterstore('zsetc', $sourceKeys));
|
||||
$this->assertEquals(
|
||||
array(array('b', 3), array('c', 5)),
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
// using an array to pass the list of source keys + options array
|
||||
$options = array('weights' => array(2, 3));
|
||||
$this->assertEquals(2, $this->redis->zinterstore('zsetc', $sourceKeys, $options));
|
||||
$this->assertEquals(
|
||||
array(array('b', 7), array('c', 12)),
|
||||
$this->redis->zrange('zsetc', 0, -1, 'withscores')
|
||||
);
|
||||
|
||||
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
|
||||
$test->redis->set('zsetFake', 'fake');
|
||||
$test->redis->zinterstore('zsetc', 2, 'zseta', 'zsetFake');
|
||||
@@ -1998,7 +2037,7 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
|
||||
function testInfo() {
|
||||
$serverInfo = $this->redis->info();
|
||||
|
||||
$this->assertType('array', $serverInfo);
|
||||
$this->assertInternalType('array', $serverInfo);
|
||||
$this->assertNotNull($serverInfo['redis_version']);
|
||||
$this->assertGreaterThan(0, $serverInfo['uptime_in_seconds']);
|
||||
$this->assertGreaterThan(0, $serverInfo['total_connections_received']);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once(__DIR__ . '/../lib/Predis.php');
|
||||
require_once(__DIR__ . '/../lib/Predis_Compatibility.php');
|
||||
require_once(__DIR__ . '/../test/PredisShared.php');
|
||||
|
||||
Reference in New Issue
Block a user