Compare commits

...

90 Commits

Author SHA1 Message Date
Daniele Alessandri c81e02b0ba Merge branch 'master' into version-0.5 2010-01-23 16:01:19 +01:00
Daniele Alessandri 1be9bef159 Updated CHANGELOG 2010-01-23 16:01:03 +01:00
Daniele Alessandri 7fa935f827 Implemented a factory method for creating server profiles instances. 2010-01-23 15:55:34 +01:00
Daniele Alessandri afdc79f97f Added tests for BGREWRITEAOF. 2010-01-23 15:31:53 +01:00
Daniele Alessandri 6cb9663539 Added missing support for BGREWRITEAOF for Redis >= 1.2.0 2010-01-23 12:54:58 +01:00
Daniele Alessandri 8622dd8b05 Added the CHANGELOG file. 2010-01-23 12:41:45 +01:00
Daniele Alessandri 21acb300a7 The command ListPopLastPushHead (RPOPLPUSH) is now defined as an inline command instead of bulk after a change in Redis 1.2.1. The old bulk RPOPLPUSH has been preserved and renamed in ListPopLastPushHeadBulk, so that you can override the current server profile if you need the old (and uncorrect) behaviour when connecting to a Redis 1.2.0 instance. 2010-01-23 12:33:10 +01:00
Daniele Alessandri 35016ba4b0 Changed the naming convention of the predefined RedisServerProfile derived classes. 2010-01-09 12:36:46 +01:00
Daniele Alessandri ab2842c100 Minor changes in code formatting. 2010-01-09 12:14:40 +01:00
Daniele Alessandri 91543d776f Adjusted Predis\Commands\BackgroundSave according to the new behavior of BGSAVE in Redis 1.2. 2010-01-09 12:00:36 +01:00
Daniele Alessandri 84fb4390f9 Using isset to check if prefix handlers have been initialized is faster. 2010-01-09 11:42:16 +01:00
Daniele Alessandri 8b152f0ea3 Added checks for errors returned by read and write operations on sockets. 2010-01-09 11:28:57 +01:00
Daniele Alessandri e01feda91f Updated the README. 2010-01-09 10:01:47 +01:00
Daniele Alessandri 15c81fca6f Bumping year in the LICENSE file. 2010-01-09 09:49:20 +01:00
Daniele Alessandri 75fad0a027 Implemented Response::read. This new method groups Response::getPrefix and Response::getHeader (and reduces the overhead of unnecessary method calls). 2010-01-07 13:48:14 +01:00
Daniele Alessandri 46dd3d6f19 Improved the internals of MultiExecBlock::execute (slight reduction in memory usage; check for out-of-sync conditions between the client and the server) 2010-01-06 12:13:51 +01:00
Daniele Alessandri d51e8e0c25 Greatly improved the code that initially handles replies getting the correct reply handler. Also, performances might have improved a bit. 2010-01-06 11:47:05 +01:00
Daniele Alessandri 1d3e8cea59 Reduced memory consumption for pipelines 2010-01-06 11:03:27 +01:00
Daniele Alessandri 03886d9a78 Merge branch 'blpop'
Conflicts:
	lib/Predis.php
2010-01-06 10:37:03 +01:00
Daniele Alessandri 2577f6a2cb Added tests for BLPOP and BRPOP. They are not really that great as they are missing a concurrent RPUSHing client, but they are enough for now. 2010-01-02 22:09:27 +01:00
Daniele Alessandri 5641983059 Fixed E_NOTICE messages in Predis\Response::getPrefixHandler on undefined handlers (unknown prefixes received from the server). 2010-01-01 20:44:28 +01:00
Daniele Alessandri 0bac9308b5 Fixed E_NOTICE messages in Predis\RedisServerProfile::createCommand on undefined commands. 2010-01-01 20:32:24 +01:00
Daniele Alessandri d12694c271 Predis\CommandPipeline::execute and Predis\MultiExecBlock::execute are no more limited to accepting only instances of Closure, now every kind of callable object can be passed as argument. 2010-01-01 20:19:34 +01:00
Daniele Alessandri 362cdf4d5a Use the new ternary short cut "?:" where it helps with readability. 2010-01-01 18:55:32 +01:00
Daniele Alessandri 04c481b3d7 Removed a bunch of unmeaningful TODOs end notes. 2010-01-01 18:42:13 +01:00
Daniele Alessandri 238baf7dc8 Implemented Predis\RedisServerProfile::compareWith, usefult to compare two different profiles. Its current behavior is the very same as PHP's version_compare. 2010-01-01 18:35:15 +01:00
Daniele Alessandri 9dae351819 Casting a instance of Predis\RedisServerProfile to string returns its associated version string. 2010-01-01 18:11:37 +01:00
Daniele Alessandri d34fc18ea8 Reverted a bad versioning idea. The Predis\RedisServer__Futures class will always be availabe and it represents the current development branch of Redis. 2010-01-01 18:09:03 +01:00
Daniele Alessandri cd8604b489 Removed Predis\Client::registerCommand and Predis\Client::registerCommands as they are rarely used. The methods of the same name available in RedisServerProfile (and its derivates) serve the same purpose, use them from now on. 2010-01-01 17:46:34 +01:00
Daniele Alessandri 99ad5aa4a5 Implemented Predis\Client::getProfile. 2010-01-01 17:37:26 +01:00
Daniele Alessandri 2e5549b316 Renamed Predis\Client::setServerProfile to Predis\Client::setProfile. 2010-01-01 17:35:42 +01:00
Daniele Alessandri d719a26406 Switch to string-based versions for RedisServerProfile classes. 2010-01-01 17:25:27 +01:00
Daniele Alessandri 2a06d84a7b Throw a more meaningful exception if the server does not respond with a +QUEUED status reply to commands issued in a MULTI / EXEC context. 2009-12-31 14:11:24 +01:00
Daniele Alessandri 1f9e6143bf Commands issued with a MultiExecBlock now return ResponseQueued instances to the caller. 2009-12-31 14:05:12 +01:00
Daniele Alessandri 77f885c233 Merge branch 'multi_exec' 2009-12-31 13:48:20 +01:00
Daniele Alessandri db6e40df98 Added tests for MULTI / EXEC. 2009-12-31 13:00:27 +01:00
Daniele Alessandri e637881c2d Force the test suite to load the server profile for Redis edge versions (development unstable). 2009-12-31 12:18:34 +01:00
Daniele Alessandri 31234d694e Bugfix: ListPopFirstBlocking is actually BLPOP, not BRPOP. This is what happens when you write code while thinking about something else... 2009-12-30 21:57:51 +01:00
Daniele Alessandri a4e067891a Implemented RedisServerProfile::supportsCommand. 2009-12-30 13:49:48 +01:00
Daniele Alessandri bf19df180c Introduced a first draft of a new way to internally check for responses to enqueued commands. 2009-12-30 11:51:39 +01:00
Daniele Alessandri 7c6e03edae Removed the default value for the read_write_timeout when initializing the connection stream. Now the timeout for r/w operations on the stream is set only if it has been set in the ConnectionParameters instance, otherwise the system default will be implicitly used (the default is usually 60 seconds). 2009-12-30 10:38:56 +01:00
Daniele Alessandri ee739ff843 Implemented the __isset magic method for the ConnectionParameters class (it is useful to check if a parameter has been set). 2009-12-30 10:30:08 +01:00
Daniele Alessandri fcecd2579a Added "connection_timeout" and "read_write_timeout" as optional arguments for the ConnectionParameters class. 2009-12-30 10:25:06 +01:00
Daniele Alessandri f3aeecef37 Added BLPOP and BRPOP. 2009-12-30 09:35:46 +01:00
Daniele Alessandri 55c40afcd8 Bugfix: return an empty string instead of null when the data length of a bulk reply is 0. 2009-12-29 14:55:26 +01:00
Daniele Alessandri 1626f9658c New Predis\Client::multiExec method added. 2009-12-28 00:29:51 +01:00
Daniele Alessandri f4b0f664e7 Implemented the new Predis\MultiExecBlock class to wrap commands issued inside of MULTI + EXEC. 2009-12-28 00:23:00 +01:00
Daniele Alessandri 5c95b9cdcc Do not parse the response to a command if we get a QUEUED status reply from the server. 2009-12-27 23:21:46 +01:00
Daniele Alessandri a13d0e4d72 Started hacking a bit on the new MULTI and EXEC commands. 2009-12-27 22:44:47 +01:00
Daniele Alessandri abbc9108e0 Fixed another E_STRICT notice that was being raised when using a pipeline. 2009-12-27 11:42:18 +01:00
Daniele Alessandri b757afe492 Removed a superfluous method call. 2009-12-27 10:57:23 +01:00
Daniele Alessandri 75a06019f8 Fixed E_STRICT notices that were being raised by PHP due to a slightly different method signature used for two command classes. 2009-12-27 10:53:29 +01:00
Daniele Alessandri 51710682c7 ZSetReverseRange now inherits from ZSetRange as the two commands share the same behaviour. This change allowed us to remove some code duplication. 2009-12-27 10:48:41 +01:00
Daniele Alessandri f82d11a8db Changed the name of Predis\Client::createCommandInstance into Predis\Client::createCommand. 2009-12-27 10:33:02 +01:00
Daniele Alessandri 6814845e3f Removed a wrong type-check in Predis\Client::setupConnection that was breaking the initialization of a cluster of connections when using an array of URI strings as parameters. 2009-12-26 19:42:45 +01:00
Daniele Alessandri e8a0f3f627 Fix for a warning emitted by PHP when passing an array of strings parameters to Predis\Client::create. 2009-12-26 19:39:18 +01:00
Daniele Alessandri 6e39491692 Changed the returned string used to hash a Connection instance when using a cluster of connections. IMPORTANT NOTE: if you are using a version of Predis older than this commit, then this change will surely have an impact on your existing partitioned data as it changes the distribution of server nodes over the ring. 2009-12-25 22:04:24 +01:00
Daniele Alessandri e5c3123d88 Updated TODO. 2009-12-25 21:54:04 +01:00
Daniele Alessandri 6d43827af9 Merge branch 'server_compat'
Conflicts:
	lib/Predis.php
2009-12-25 21:25:40 +01:00
Daniele Alessandri 4a4e4b5a72 Updated the README with the new parameters for Predis\Client. The old signature Predis\Client(, ) is now completely deprecated and it does not work anymore. 2009-12-25 21:12:54 +01:00
Daniele Alessandri 8eb51ec0d1 Updated the test suite to work with the new parameters for Predis\Client. 2009-12-25 21:11:08 +01:00
Daniele Alessandri 47bb83bbb2 Type checking + minor fixes + more readable code for Predis\Client::__construct and Predis\Client::create. 2009-12-25 20:51:17 +01:00
Daniele Alessandri e64333d77b Complete rewrite of the client construction and initialization bits. 2009-12-25 19:54:12 +01:00
Daniele Alessandri 627433cef8 Extended the tests for ZRANGE and ZREVRANGE to cover the newly added "WITHSCORES" option. 2009-12-23 22:05:04 +01:00
Daniele Alessandri 822a3e56e2 Implemented the "WITHSCORES" option for ZRANGE and ZREVRANGE. 2009-12-23 21:54:53 +01:00
Daniele Alessandri d9b304f9e3 Merge branch 'cmd_zincrby' 2009-12-19 10:49:34 +01:00
Daniele Alessandri 81484b3351 Added tests for Predis\Commands\ZSetIncrementBy (ZINCRBY). 2009-12-19 10:46:09 +01:00
Daniele Alessandri d3a62d68bb Fixed the return value of Predis\Commands\ZSetIncrementBy as it does not return a boolean value but the current score after the increment operation. 2009-12-19 10:45:19 +01:00
Daniele Alessandri 20e416306c Added support for key tags: instead of hashing the full key, we hash only the portion enclosed within curly brackets. 2009-12-18 22:57:16 +01:00
Daniele Alessandri 3ccbff4277 The second parameter for RedisServerProfile::createCommandInstance is now optional. 2009-12-18 22:02:30 +01:00
Daniele Alessandri 6e76fbf660 Moved the default server profile class name to a private static variable of the Client class. 2009-12-18 21:59:00 +01:00
Daniele Alessandri 88cda9e52c Added the new public method Client::setServerProfile. 2009-12-18 21:29:44 +01:00
Daniele Alessandri 876ac2ec7c Renamed class RedisServerCompatibility to RedisServerProfile. 2009-12-18 21:24:19 +01:00
Daniele Alessandri e57348720f Just removed a bunch of unuseful comments... 2009-12-18 21:16:24 +01:00
Daniele Alessandri f811877c87 More trivial changes for HashRing::add and HashRing::remove. 2009-12-18 21:08:42 +01:00
Daniele Alessandri d3115e6259 Trivial changes in HashRing::getNodeKey. 2009-12-18 21:04:44 +01:00
Daniele Alessandri ca7f3e294c Removed the rather superfluous private method ConnectionCluster::getConnectionFromRing. 2009-12-18 20:48:04 +01:00
Daniele Alessandri bcfa64f431 Moved the hash calculation for a command from ConnectionCluster to the command instance itself. 2009-12-18 20:43:35 +01:00
Daniele Alessandri 3428529be6 Client::executeCommandInternal must accept IConnection types! Stupid bugs are indeed stupid. 2009-12-16 00:23:55 +01:00
Daniele Alessandri b1edc31af3 When using a ConnectionCluster (sharding data over multiple servers), disallow sending commands that cannot be hashed by a key argument. 2009-12-14 18:15:10 +01:00
Daniele Alessandri 344ec44059 Refactored Client::executeCommand and introduced the new method Client::executeCommandOnShards which is useful to execute commands on all the connections registered in a ConnectionCluster instance. 2009-12-14 18:02:54 +01:00
Daniele Alessandri 8d4958a516 The second parameter for Client::createCommandInstance is now optional. 2009-12-14 17:57:17 +01:00
Daniele Alessandri b777daa535 Slightly improved the internals of Command::getArgument and Command::getArguments. 2009-12-14 17:54:11 +01:00
Daniele Alessandri 177120e1a2 The private method computeHash of ConnectionCluster is now a static method. 2009-12-14 17:47:10 +01:00
Daniele Alessandri a84c9bdac7 ConnectionCluster now implements the IteratorAggregate interface, thus enabling iterations over the registered connections simply by using a foreach loop. 2009-12-14 17:43:30 +01:00
Daniele Alessandri c7cd2b67e0 Same fix as commit 755c252 in master for the short alias of \Predis\Commands\Decrement 2009-12-04 21:09:38 +01:00
Daniele Alessandri cfcb635c24 Predis\Client now uses the new compatibility profiles, though it is still hardcoded which profile to load. 2009-11-29 13:38:04 +01:00
Daniele Alessandri d0d51257c9 Added compatibility profiles for Redis server versions 1.0 and the upcoming 1.2. 2009-11-29 13:16:42 +01:00
Daniele Alessandri a70c5b0800 Added the new abstract class 'RedisServerCompatibility'. Its subclassess will be used to define a set compatibility profiles for each version of the Redis server. The only drawback is that the selected compatibility profile will be shared among multiple connections when using client-side sharding. 2009-11-29 13:09:08 +01:00
Daniele Alessandri af810d9613 Implemented ZINCRBY (Class: \Predis\Commands\ZSetIncrementBy) 2009-11-20 22:23:42 +01:00
7 changed files with 774 additions and 320 deletions
+14
View File
@@ -0,0 +1,14 @@
v0.5.1
* RPOPLPUSH has been changed from bulk command to inline command in Redis
1.2.1, so ListPopLastPushHead now extends InlineCommand. The old RPOPLPUSH
behavior is still available via the ListPopLastPushHeadBulk class so that
you can override the server profile if you need the old (and uncorrect)
behaviour when connecting to a Redis 1.2.0 instance.
* Added missing support for BGREWRITEAOF for Redis >= 1.2.0
* Implemented a factory method for the RedisServerProfile class to ease the
creation of new server profile instances based on a version string.
v0.5.0
* First versioned release of Predis
+3 -3
View File
@@ -1,5 +1,5 @@
Copyright (c) 2009 Daniele Alessandri
Copyright (c) 2009-2010 Daniele Alessandri
qq
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
OTHER DEALINGS IN THE SOFTWARE.
+15 -6
View File
@@ -5,9 +5,13 @@
Predis is a flexible and feature-complete PHP client library for the Redis key-value
database.
Predis is currently a work-in-progress and it targets PHP >= 5.3, though it is highly
due to be backported to PHP >= 5.2.6 as soon as the public API and the internal design
on the main branch will be considered stable enough.
Predis is currently a work-in-progress and it comes in two flavors:
- the mainline client library, which targets PHP 5.3.x and leverages a lot of the
features introduced in this new version of the PHP interpreter.
- a backport to PHP 5.2.x for those who can not upgrade their environment yet
(it admittedly has a lower priority compared to the mainline library, although we
try to keep the two versions aligned as much as possible).
Please refer to the TODO file to see which issues are still pending and what is due
to be implemented soon in Predis.
@@ -23,6 +27,9 @@ to be implemented soon in Predis.
## Quick examples ##
See the [official wiki](http://wiki.github.com/nrk/predis) of the project for a more
complete coverage of all the features available in Predis.
### Connecting to a local instance of Redis ###
You don't have to specify a tcp host and port when connecting to Redis instances
@@ -38,7 +45,7 @@ running on the localhost on the default port:
Pipelining helps with performances when there is the need to issue many commands
to a server in one go:
$redis = new Predis\Client('10.0.0.1', 6379);
$redis = new Predis\Client('redis://10.0.0.1:6379/');
$replies = $redis->pipeline(function($pipe) {
$pipe->ping();
$pipe->incrby('counter', 10);
@@ -81,7 +88,7 @@ client instance at runtime. Actually, it is easier done than said:
}
$redis = new Predis\Client();
$redis->registerCommand('BrandNewRedisCommand', 'newcmd');
$redis->getProfile()->registerCommand('BrandNewRedisCommand', 'newcmd');
$redis->newcmd();
@@ -105,13 +112,15 @@ variable set to E_ALL.
## Dependencies ##
- PHP >= 5.3
- PHP >= 5.3.0 (for the mainline client library)
- PHP >= 5.2.6 (for the backported client library)
- PHPUnit (needed to run the test suite)
## Links ##
### Project ###
- [Source code](http://github.com/nrk/predis/)
- [Wiki](http://wiki.github.com/nrk/predis/)
- [Issue tracker](http://github.com/nrk/predis/issues)
### Related ###
+2 -17
View File
@@ -1,21 +1,6 @@
* Authentication and database selection should be handled transparently by
the client.
* The current behaviour of sending, by default, unshardable commands to the
first registered connection of a ConnectionCluster instance needs to be
verified.
* Documentation! The README is obviously not enought to show how to use
Predis as it does not cover all of its features.
* The included test suite covers almost all the Redis server commands, but a
full battery of tests targeting specific functions of this library is still
missing.
* Support for pipelining commands on one or more connections works, but it
could be optimized for better performances with a cache of computed commands
hashes, but the memory impact still needs to be evalued.
* Add the possibility of flushing the command buffer from inside of a pipeline.
* Switching to/from instances of Connection and ConnectionCluster should be
transparent to the user. Using a ConnectionCluster instance when there is
only one active connection has an unnecessary overhead.
+609 -293
View File
File diff suppressed because it is too large Load Diff
+19 -1
View File
@@ -21,11 +21,13 @@ class RC {
const EXCEPTION_NO_SUCH_KEY = 'no such key';
const EXCEPTION_OUT_OF_RANGE = 'index out of range';
const EXCEPTION_INVALID_DB_IDX = 'invalid DB index';
const EXCEPTION_EXEC_NO_MULTI = 'EXEC without MULTI';
private static $_connection;
private static function createConnection() {
$connection = new Predis\Client(RC::SERVER_HOST, RC::SERVER_PORT);
$serverProfile = Predis\RedisServerProfile::get('dev');
$connection = new Predis\Client(array('host' => RC::SERVER_HOST, 'port' => RC::SERVER_PORT), $serverProfile);
$connection->connect();
$connection->selectDatabase(RC::DEFAULT_DATABASE);
return $connection;
@@ -45,6 +47,22 @@ class RC {
}
}
public static function helperForBlockingPops($op) {
// TODO: I admit that this helper is kinda lame and it does not run
// 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');
fwrite($handle, "<?php
require '../lib/Predis.php';
\$redis = Predis\Client::create('$redisUri');
\$redis->rpush('{$op}1', 'a');
\$redis->rpush('{$op}2', 'b');
\$redis->rpush('{$op}3', 'c');
\$redis->rpush('{$op}1', 'd');
?>");
pclose($handle);
}
public static function getArrayOfNumbers() {
return array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
+112
View File
@@ -45,6 +45,25 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->assertFalse($this->redis->isConnected());
}
function testMultiExec() {
// NOTE: due to a limitation in the current implementation of Predis\Client,
// the replies returned by Predis\Command\Exec are not parsed by their
// 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->assertEquals(array('PONG', 'hello', 'redis'), $this->redis->exec());
$this->assertTrue($this->redis->multi());
$this->assertEquals(array(), $this->redis->exec());
// should throw an exception when trying to EXEC without having previously issued MULTI
RC::testForServerException($this, RC::EXCEPTION_EXEC_NO_MULTI, function($test) {
$test->redis->exec();
});
}
/* commands operating on string values */
@@ -535,6 +554,60 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
});
}
function testListBlockingPopFirst() {
// TODO: this test does not cover all the aspects of BLPOP/BRPOP as it
// does not run with a concurrent client pushing items on lists.
RC::helperForBlockingPops('blpop');
// BLPOP on one key
$start = time();
$item = $this->redis->blpop('blpop3', 5);
$this->assertEquals((float)(time() - $start), 0, '', 1);
$this->assertEquals($item, array('blpop3', 'c'));
// BLPOP on more than one key
$poppedItems = array();
while ($item = $this->redis->blpop('blpop1', 'blpop2', 1)) {
$poppedItems[] = $item;
}
$this->assertEquals(
array(array('blpop1', 'a'), array('blpop1', 'd'), array('blpop2', 'b')),
$poppedItems
);
// check if BLPOP timeouts as expected on empty lists
$start = time();
$this->redis->blpop('blpop4', 2);
$this->assertEquals((float)(time() - $start), 2, '', 1);
}
function testListBlockingPopLast() {
// TODO: this test does not cover all the aspects of BLPOP/BRPOP as it
// does not run with a concurrent client pushing items on lists.
RC::helperForBlockingPops('brpop');
// BRPOP on one key
$start = time();
$item = $this->redis->brpop('brpop3', 5);
$this->assertEquals((float)(time() - $start), 0, '', 1);
$this->assertEquals($item, array('brpop3', 'c'));
// BRPOP on more than one key
$poppedItems = array();
while ($item = $this->redis->brpop('brpop1', 'brpop2', 1)) {
$poppedItems[] = $item;
}
$this->assertEquals(
array(array('brpop1', 'd'), array('brpop1', 'a'), array('brpop2', 'b')),
$poppedItems
);
// check if BRPOP timeouts as expected on empty lists
$start = time();
$this->redis->brpop('brpop4', 2);
$this->assertEquals((float)(time() - $start), 2, '', 1);
}
/* commands operating on sets */
@@ -866,6 +939,26 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
});
}
function testZsetIncrementBy() {
$this->assertEquals(1, $this->redis->zsetIncrementBy('zsetDoesNotExist', 1, 'foo'));
$this->assertEquals('zset', $this->redis->type('zsetDoesNotExist'));
RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());
$this->assertEquals(-5, $this->redis->zsetIncrementBy('zset', 5, 'a'));
$this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'b'));
$this->assertEquals(10, $this->redis->zsetIncrementBy('zset', 0, 'c'));
$this->assertEquals(0, $this->redis->zsetIncrementBy('zset', -20, 'd'));
$this->assertEquals(2, $this->redis->zsetIncrementBy('zset', 2, 'd'));
$this->assertEquals(-10, $this->redis->zsetIncrementBy('zset', -30, 'e'));
$this->assertEquals(1, $this->redis->zsetIncrementBy('zset', 1, 'x'));
// wrong type
$this->redis->set('foo', 'bar');
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->zsetIncrementBy('foo', 1, 'a');
});
}
function testZsetRemove() {
RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());
@@ -921,6 +1014,16 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->zsetRange('zset', -100, 100)
);
$this->assertEquals(
array_values(array_keys($zset)),
$this->redis->zsetRange('zset', -100, 100)
);
$this->assertEquals(
array(array('a', -10), array('b', 0), array('c', 10)),
$this->redis->zsetRange('zset', 0, 2, 'withscores')
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('foo', 'bar');
$test->redis->zsetRange('foo', 0, -1);
@@ -970,6 +1073,11 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->redis->zsetReverseRange('zset', -100, 100)
);
$this->assertEquals(
array(array('f', 30), array('e', 20), array('d', 20)),
$this->redis->zsetReverseRange('zset', 0, 2, 'withscores')
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('foo', 'bar');
$test->redis->zsetReverseRange('foo', 0, -1);
@@ -1229,6 +1337,10 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
$this->assertTrue($this->redis->backgroundSave());
}
function testBackgroundRewriteAppendOnlyFile() {
$this->assertTrue($this->redis->backgroundRewriteAppendOnlyFile());
}
function testLastSave() {
$this->assertGreaterThan(0, $this->redis->lastSave());
}