mirror of
https://github.com/predis/predis.git
synced 2026-08-18 14:04:15 +00:00
Compare commits
90 Commits
v0.6.2-PHP5.2
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| c81e02b0ba | |||
| 1be9bef159 | |||
| 7fa935f827 | |||
| afdc79f97f | |||
| 6cb9663539 | |||
| 8622dd8b05 | |||
| 21acb300a7 | |||
| 35016ba4b0 | |||
| ab2842c100 | |||
| 91543d776f | |||
| 84fb4390f9 | |||
| 8b152f0ea3 | |||
| e01feda91f | |||
| 15c81fca6f | |||
| 75fad0a027 | |||
| 46dd3d6f19 | |||
| d51e8e0c25 | |||
| 1d3e8cea59 | |||
| 03886d9a78 | |||
| 2577f6a2cb | |||
| 5641983059 | |||
| 0bac9308b5 | |||
| d12694c271 | |||
| 362cdf4d5a | |||
| 04c481b3d7 | |||
| 238baf7dc8 | |||
| 9dae351819 | |||
| d34fc18ea8 | |||
| cd8604b489 | |||
| 99ad5aa4a5 | |||
| 2e5549b316 | |||
| d719a26406 | |||
| 2a06d84a7b | |||
| 1f9e6143bf | |||
| 77f885c233 | |||
| db6e40df98 | |||
| e637881c2d | |||
| 31234d694e | |||
| a4e067891a | |||
| bf19df180c | |||
| 7c6e03edae | |||
| ee739ff843 | |||
| fcecd2579a | |||
| f3aeecef37 | |||
| 55c40afcd8 | |||
| 1626f9658c | |||
| f4b0f664e7 | |||
| 5c95b9cdcc | |||
| a13d0e4d72 | |||
| abbc9108e0 | |||
| b757afe492 | |||
| 75a06019f8 | |||
| 51710682c7 | |||
| f82d11a8db | |||
| 6814845e3f | |||
| e8a0f3f627 | |||
| 6e39491692 | |||
| e5c3123d88 | |||
| 6d43827af9 | |||
| 4a4e4b5a72 | |||
| 8eb51ec0d1 | |||
| 47bb83bbb2 | |||
| e64333d77b | |||
| 627433cef8 | |||
| 822a3e56e2 | |||
| d9b304f9e3 | |||
| 81484b3351 | |||
| d3a62d68bb | |||
| 20e416306c | |||
| 3ccbff4277 | |||
| 6e76fbf660 | |||
| 88cda9e52c | |||
| 876ac2ec7c | |||
| e57348720f | |||
| f811877c87 | |||
| d3115e6259 | |||
| ca7f3e294c | |||
| bcfa64f431 | |||
| 3428529be6 | |||
| b1edc31af3 | |||
| 344ec44059 | |||
| 8d4958a516 | |||
| b777daa535 | |||
| 177120e1a2 | |||
| a84c9bdac7 | |||
| c7cd2b67e0 | |||
| cfcb635c24 | |||
| d0d51257c9 | |||
| a70c5b0800 | |||
| af810d9613 |
@@ -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
|
||||
@@ -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
@@ -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 ###
|
||||
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
+19
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user