mirror of
https://github.com/predis/predis.git
synced 2026-09-20 15:26:46 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a170b3d81 | |||
| 17e7bce22e | |||
| 7a5d6bac3e | |||
| 9d6c031ead | |||
| 692718afb4 | |||
| 0776377412 | |||
| e4b0512d42 | |||
| 75ca2f8111 | |||
| 37b1c88115 | |||
| a4e6130568 | |||
| f3748e45ef | |||
| beb6c28c65 |
@@ -20,5 +20,6 @@ script:
|
|||||||
- vendor/bin/phpunit -c phpunit.xml.travisci
|
- vendor/bin/phpunit -c phpunit.xml.travisci
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
- php: hhvm
|
||||||
- php: hhvm-nightly
|
- php: hhvm-nightly
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|||||||
+6
-1
@@ -1,6 +1,11 @@
|
|||||||
v1.0.1 (2014-xx-xx)
|
v1.0.1 (2015-01-02)
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
|
- Added `BITPOS` to the server profile for Redis 2.8.
|
||||||
|
|
||||||
|
- Connection timeout for read/write operations can now be set for UNIX sockets
|
||||||
|
where the underlying connection uses PHP's stream.
|
||||||
|
|
||||||
- __FIX__: broken values returned by `Predis\Collection\Iterator\SortedSetKey`
|
- __FIX__: broken values returned by `Predis\Collection\Iterator\SortedSetKey`
|
||||||
when iterating sorted set containing integer members (ISSUE #216).
|
when iterating sorted set containing integer members (ISSUE #216).
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2009-2014 Daniele Alessandri
|
Copyright (c) 2009-2015 Daniele Alessandri
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ desc = "Flexible and feature-complete PHP client library for Redis"
|
|||||||
homepage = "http://github.com/nrk/predis"
|
homepage = "http://github.com/nrk/predis"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
stability = "devel"
|
stability = "stable"
|
||||||
channel = "pear.nrk.io"
|
channel = "pear.nrk.io"
|
||||||
|
|
||||||
author = "Daniele Alessandri \"nrk\" <suppakilla@gmail.com>"
|
author = "Daniele Alessandri \"nrk\" <suppakilla@gmail.com>"
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ use Predis\Transaction\MultiExec as MultiExecTransaction;
|
|||||||
*/
|
*/
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
const VERSION = '1.0.1-dev';
|
const VERSION = '1.0.1';
|
||||||
|
|
||||||
protected $connection;
|
protected $connection;
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|||||||
@@ -123,6 +123,14 @@ class StreamConnection extends AbstractConnection
|
|||||||
$this->onConnectionError(trim($errstr), $errno);
|
$this->onConnectionError(trim($errstr), $errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($parameters->read_write_timeout)) {
|
||||||
|
$rwtimeout = (float) $parameters->read_write_timeout;
|
||||||
|
$rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1;
|
||||||
|
$timeoutSeconds = floor($rwtimeout);
|
||||||
|
$timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000;
|
||||||
|
stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
return $resource;
|
return $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class RedisVersion280 extends RedisProfile
|
|||||||
|
|
||||||
/* commands operating on the key space */
|
/* commands operating on the key space */
|
||||||
'SCAN' => 'Predis\Command\KeyScan',
|
'SCAN' => 'Predis\Command\KeyScan',
|
||||||
|
|
||||||
/* commands operating on string values */
|
/* commands operating on string values */
|
||||||
'BITPOS' => 'Predis\Command\StringBitPos',
|
'BITPOS' => 'Predis\Command\StringBitPos',
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class RedisVersion300 extends RedisProfile
|
|||||||
|
|
||||||
/* commands operating on the key space */
|
/* commands operating on the key space */
|
||||||
'SCAN' => 'Predis\Command\KeyScan',
|
'SCAN' => 'Predis\Command\KeyScan',
|
||||||
|
|
||||||
/* commands operating on string values */
|
/* commands operating on string values */
|
||||||
'BITPOS' => 'Predis\Command\StringBitPos',
|
'BITPOS' => 'Predis\Command\StringBitPos',
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use Predis\Profile;
|
|||||||
*/
|
*/
|
||||||
abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
|
abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
protected $predisRequirements = array();
|
||||||
protected $redisServerVersion = null;
|
protected $redisServerVersion = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,7 +264,7 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
!empty($annotations['method']['requiresRedisVersion']) &&
|
!empty($annotations['method']['requiresRedisVersion']) &&
|
||||||
in_array('connected', $annotations['method']['group'])
|
in_array('connected', $annotations['method']['group'])
|
||||||
) {
|
) {
|
||||||
$this->required['requiresRedisVersion'] = $annotations['method']['requiresRedisVersion'][0];
|
$this->predisRequirements['requiresRedisVersion'] = $annotations['method']['requiresRedisVersion'][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,12 +273,12 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
protected function checkRequiredRedisVersion()
|
protected function checkRequiredRedisVersion()
|
||||||
{
|
{
|
||||||
if (!isset($this->required['requiresRedisVersion'])) {
|
if (!isset($this->predisRequirements['requiresRedisVersion'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$srvVersion = $this->getRedisServerVersion();
|
$srvVersion = $this->getRedisServerVersion();
|
||||||
$expectation = explode(' ', $this->required['requiresRedisVersion'], 2);
|
$expectation = explode(' ', $this->predisRequirements['requiresRedisVersion'], 2);
|
||||||
|
|
||||||
if (count($expectation) === 1) {
|
if (count($expectation) === 1) {
|
||||||
$expOperator = '>=';
|
$expOperator = '>=';
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
namespace Predis\Command;
|
namespace Predis\Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group commands
|
* @group commands
|
||||||
* @group realm-string
|
* @group realm-string
|
||||||
@@ -21,6 +22,7 @@ class StringBitPosTest extends PredisCommandTestCase
|
|||||||
{
|
{
|
||||||
return 'Predis\Command\StringBitPos';
|
return 'Predis\Command\StringBitPos';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -28,6 +30,7 @@ class StringBitPosTest extends PredisCommandTestCase
|
|||||||
{
|
{
|
||||||
return 'BITPOS';
|
return 'BITPOS';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group disconnected
|
* @group disconnected
|
||||||
*/
|
*/
|
||||||
@@ -35,10 +38,13 @@ class StringBitPosTest extends PredisCommandTestCase
|
|||||||
{
|
{
|
||||||
$arguments = array('key', 0, 1, 10);
|
$arguments = array('key', 0, 1, 10);
|
||||||
$expected = array('key', 0, 1, 10);
|
$expected = array('key', 0, 1, 10);
|
||||||
|
|
||||||
$command = $this->getCommand();
|
$command = $this->getCommand();
|
||||||
$command->setArguments($arguments);
|
$command->setArguments($arguments);
|
||||||
|
|
||||||
$this->assertSame($expected, $command->getArguments());
|
$this->assertSame($expected, $command->getArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group disconnected
|
* @group disconnected
|
||||||
*/
|
*/
|
||||||
@@ -47,25 +53,33 @@ class StringBitPosTest extends PredisCommandTestCase
|
|||||||
$raw = 10;
|
$raw = 10;
|
||||||
$expected = 10;
|
$expected = 10;
|
||||||
$command = $this->getCommand();
|
$command = $this->getCommand();
|
||||||
|
|
||||||
$this->assertSame($expected, $command->parseResponse($raw));
|
$this->assertSame($expected, $command->parseResponse($raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group connected
|
* @group connected
|
||||||
|
* @requiresRedisVersion >= 2.8.7
|
||||||
*/
|
*/
|
||||||
public function testReturnsBitPosition()
|
public function testReturnsBitPosition()
|
||||||
{
|
{
|
||||||
$redis = $this->getClient();
|
$redis = $this->getClient();
|
||||||
|
|
||||||
$redis->setbit('key', 10, 0);
|
$redis->setbit('key', 10, 0);
|
||||||
$this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range');
|
$this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range');
|
||||||
$this->assertSame(-1, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range');
|
$this->assertSame(-1, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range');
|
||||||
$this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range');
|
$this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range');
|
||||||
|
|
||||||
$redis->setbit('key', 5, 1);
|
$redis->setbit('key', 5, 1);
|
||||||
$this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range');
|
$this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range');
|
||||||
$this->assertSame(5, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range');
|
$this->assertSame(5, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range');
|
||||||
$this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range');
|
$this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group connected
|
* @group connected
|
||||||
|
* @requiresRedisVersion >= 2.8.7
|
||||||
* @expectedException \Predis\Response\ServerException
|
* @expectedException \Predis\Response\ServerException
|
||||||
* @expectedExceptionMessage Operation against a key holding the wrong kind of value
|
* @expectedExceptionMessage Operation against a key holding the wrong kind of value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -340,4 +340,71 @@ class ConsumerTest extends PredisTestCase
|
|||||||
$this->assertFalse($pubsub->valid());
|
$this->assertFalse($pubsub->valid());
|
||||||
$this->assertEquals('ECHO', $consumer->echo('ECHO'));
|
$this->assertEquals('ECHO', $consumer->echo('ECHO'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group connected
|
||||||
|
*/
|
||||||
|
public function testPubSubAgainstRedisServerBlocking()
|
||||||
|
{
|
||||||
|
$parameters = array(
|
||||||
|
'host' => REDIS_SERVER_HOST,
|
||||||
|
'port' => REDIS_SERVER_PORT,
|
||||||
|
'database' => REDIS_SERVER_DBNUM,
|
||||||
|
'read_write_timeout' => -1, // -1 to set blocking reads
|
||||||
|
);
|
||||||
|
|
||||||
|
$options = array('profile' => REDIS_SERVER_VERSION);
|
||||||
|
|
||||||
|
// create consumer before forking so the child can disconnect it
|
||||||
|
$consumer = new Client($parameters, $options);
|
||||||
|
$consumer->connect();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fork
|
||||||
|
* parent: consumer
|
||||||
|
* child: producer
|
||||||
|
*/
|
||||||
|
if ($childPID = pcntl_fork()) {
|
||||||
|
$messages = array();
|
||||||
|
|
||||||
|
$pubsub = new PubSubConsumer($consumer);
|
||||||
|
$pubsub->subscribe('channel:foo');
|
||||||
|
|
||||||
|
foreach ($pubsub as $message) {
|
||||||
|
if ($message->kind !== 'message') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$messages[] = ($payload = $message->payload);
|
||||||
|
if ($payload === 'QUIT') {
|
||||||
|
$pubsub->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertSame(array('message1', 'message2', 'QUIT'), $messages);
|
||||||
|
$this->assertFalse($pubsub->valid());
|
||||||
|
$this->assertEquals('ECHO', $consumer->echo('ECHO'));
|
||||||
|
|
||||||
|
// kill the child
|
||||||
|
posix_kill($childPID, SIGKILL);
|
||||||
|
} else {
|
||||||
|
// create producer, read_write_timeout = 2 because it doesn't do blocking reads anyway
|
||||||
|
$producer = new Client(array_replace($parameters, array('read_write_timeout' => 2)), $options);
|
||||||
|
$producer->connect();
|
||||||
|
|
||||||
|
$producer->publish('channel:foo', 'message1');
|
||||||
|
$producer->publish('channel:foo', 'message2');
|
||||||
|
|
||||||
|
$producer->publish('channel:foo', 'QUIT');
|
||||||
|
|
||||||
|
// sleep, giving the consumer a chance to respond to the QUIT message
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
// disconnect the consumer because otherwise it could remain stuck in blocking read
|
||||||
|
// if it failed to respond to the QUIT message
|
||||||
|
$consumer->disconnect();
|
||||||
|
|
||||||
|
// exit child
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user