Compare commits

..

81 Commits

Author SHA1 Message Date
Till Krüss 2ce537d75e bump version to v1.1.3 2020-08-18 14:00:59 -07:00
Till Krüss 7489690306 include patch files in exports just to be safe
See #642
2020-08-18 13:55:36 -07:00
Till Krüss 7376902b20 update org references 2020-08-14 10:11:49 -07:00
Till Krüss a6bd25412e remove gitter badge 2020-08-12 12:00:08 -07:00
Till Krüss 60cc950a58 remove Predis\Async from readme 2020-08-12 11:53:52 -07:00
Till Krüss db82dd9f23 format psr-4 2020-08-12 11:53:12 -07:00
Till Krüss 1bc08d9bcc add funding to composer.json; update authors 2020-08-12 11:50:57 -07:00
Till Krüss 11e4bb44d0 more reference updates to predishq 2020-08-12 11:50:07 -07:00
Till Krüss cddb849812 remove gitter 2020-08-12 11:49:42 -07:00
Till Krüss f2298dd186 update references to predishq 2020-08-12 11:49:37 -07:00
Till Krüss bceda1d8e6 Merge pull request #625 from AhmedRaafat14/add-php8-support
Support PHP 8.0 in v1.1.x
2020-08-12 08:42:08 -07:00
Till Krüss 9f87c849c5 Update .travis.yml 2020-08-12 08:41:50 -07:00
Ahmed Raafat 1382146b03 Add php 8.0 (nightly) to the lines that is allowed to faoil (allow_failures) 2020-08-12 12:22:42 +02:00
Ahmed Raafat cbc08aa5e7 Add php 8.0 to travis 2020-08-12 11:45:43 +02:00
Till Krüss de9cd905bb Update issue templates 2020-08-11 12:05:47 -07:00
Till Krüss 6dd55d7f96 move cweagans/composer-patches as dev dep 2020-08-11 11:08:18 -07:00
Till Krüss 82eb18c6c3 bump version to 1.1.2 2020-08-11 10:28:15 -07:00
Till Krüss ac6b813ba9 Merge pull request #616 from nrk/support-php-74
Support PHP 7.4 in v1.1.x
2020-08-11 09:48:35 -07:00
Till Krüss 6482956d96 patch tests
Taken from: https://github.com/yiisoft/yii/pull/4306 by @samdark
2020-08-11 09:41:04 -07:00
Till Krüss cf15dd9857 add 7.4 to travis matrix 2020-08-11 08:55:49 -07:00
Till Krüss 597c61a098 fix out of range exception test 2020-08-11 08:43:17 -07:00
Till Krüss 9aa99349b1 Merge pull request #574 from matthewbaggett/v1.1-travis-fixup
V1.1 travis fixup
2020-08-11 08:30:12 -07:00
Till Krüss b6f60f0d72 add funding 2020-08-10 17:02:18 -07:00
Till Krüss 10235d62dc adjust error message regex 2020-08-10 13:48:17 -07:00
Till Krüss ec2b1eacd2 Merge pull request #614 from nrk/revert-611-patch-2
Revert "Bring travis config up to date"
2020-08-10 13:31:37 -07:00
Till Krüss 9c3605ab33 Merge pull request #613 from nrk/revert-610-patch-1
Revert "Add more build targets"
2020-08-10 13:31:20 -07:00
Till Krüss 55e6094954 Revert "Bring travis config up to date" 2020-08-10 13:31:03 -07:00
Till Krüss 15314b726b Revert "Add more build targets" 2020-08-10 13:30:45 -07:00
Till Krüss 292604edbf fix HHVM lowercase issue
Fatal error: Uncaught Error: Keyword __HALT_COMPILER must be written in lowercase
2020-08-10 13:02:49 -07:00
Till Krüss fc8f9f5604 Merge pull request #585 from gladx/v1.1
Fix test error exception for SELECT command
2020-08-10 12:41:25 -07:00
Till Krüss 77132e6c6b Merge pull request #589 from funivan/patch-1
Fix wiki link
2020-08-10 12:40:46 -07:00
Till Krüss a7571ef0c7 Merge pull request #583 from Miljan9602/v1.1
Fixed wrong annotation for spop method.
2020-08-10 12:40:27 -07:00
Till Krüss 4901408b08 Merge pull request #611 from hannesvdvreken/patch-2
Bring travis config up to date
2020-08-10 12:29:13 -07:00
Till Krüss dd3897b755 Merge pull request #610 from hannesvdvreken/patch-1
Add more build targets
2020-08-10 12:28:53 -07:00
Hannes Van De Vreken 6e7dbe05fb Bring travis config up to date 2020-07-29 03:33:50 +02:00
Hannes Van De Vreken f0f9d68a8e Add more build targets 2020-07-29 03:18:56 +02:00
Ivan Shcherbak bb6f1ee0e3 Fix wiki link 2019-11-25 14:23:35 +02:00
Ali Yousefi ffcc4bba8c Fix test error exception for SELECT command 2019-10-06 22:10:17 +03:30
Miljan Rakita 83359dff9a Fixed wrong annotation for spop method.
Spop method has return annotation string, but it returns array.
2019-09-10 19:26:00 +02:00
Matthew Baggett 710b4f901b Apparently 5.4 and 5.5 aren't available outside of trusty? 2019-08-09 11:54:35 +02:00
Matthew Baggett f3e46683b9 Sometimes, timing-related tests (read: KeyExpireAtTest::testCanExpireKeys) can fail but then succeed on a retry. So lets automate that retry. 2019-08-09 11:07:43 +02:00
Matthew Baggett 945e05819b Rejig. 2019-08-09 10:54:47 +02:00
Matthew Baggett a64b7354e1 Travis fixup 2019-08-09 10:37:19 +02:00
Daniele Alessandri 111d100ee3 Make examples scripts executable only via CLI.
This is meant as a basic layer of protection for those cases where the whole
Predis repository is cloned into a path which is publicly exposed by the web
server.

Closes #408
2017-07-12 16:39:17 +02:00
Daniele Alessandri 893215a1d4 Push same changes of #446 to Predis\ClientContextInterface.
This also adds a couple of missing changes into the original PR.
2017-07-12 15:34:57 +02:00
Daniele Alessandri f5d8b9fe2d Merge remote-tracking branch 'github/pr/446' into v1.1 2017-07-12 15:24:15 +02:00
Daniele Alessandri 722b513cea Upgrade .php_cs configuration file for php-cs-fixer 2.x 2017-07-12 15:22:58 +02:00
Daniele Alessandri 62774c6cc5 Merge remote-tracking branch 'github/pr/442' into v1.1 2017-07-12 13:37:06 +02:00
Daniele Alessandri 8aa2ded5b0 Merge remote-tracking branch 'github/pr/445' into v1.1 2017-07-12 13:36:17 +02:00
Daniele Alessandri 795c3e41b0 Merge remote-tracking branch 'github/pr/434' into v1.1 2017-07-12 13:31:24 +02:00
Daniele Alessandri 59e616b124 Remove broken badge.
Looks like hhvm.h4cc.de is dead.

[ci skip]
2017-07-12 13:30:52 +02:00
Daniele Alessandri 157f658f0b Fix iterators abstractions for HSCAN and ZSCAN when using PHP 7.2.
Closes #488.
2017-07-12 11:59:35 +02:00
Daniele Alessandri 343afd312a Fix wrong CRC16 calculated on integer value.
Closes #450.
2017-07-12 11:29:25 +02:00
Daniele Alessandri d77b77bbd9 Merge remote-tracking branch 'github/pr/443' into v1.1 2017-07-12 10:59:41 +02:00
gitomato 34b678192f Add string type to $keys argument
Reveals the ability to use a string for $keys argument.
2017-06-29 10:25:14 +02:00
Jorrit Schippers 4de246cfee Correct link to GitHub releases page 2017-06-27 09:35:15 +02:00
Anatoly Pashin 6fd6933580 Create .travis.yml 2017-06-11 00:28:43 +10:00
Anatoly Pashin c7b38abe71 use trusty dist 2017-06-09 18:05:11 +10:00
Anatoly Pashin 574ef78f86 fix typehint 2017-06-09 17:57:00 +10:00
Andrii Volin 1ebabaf8f8 fix typo in tests/README.md 2017-05-01 17:12:25 +03:00
Daniele Alessandri 98ec0cc27e Merge remote-tracking branch 'github/pr/376' into v1.1
[ci skip]
2016-11-22 15:32:30 +01:00
Daniele Alessandri caf8a46cbb Merge remote-tracking branch 'github/pr/373' into v1.1
[ci skip]
2016-11-22 15:30:42 +01:00
Daniele Alessandri 944a16d7c0 Merge remote-tracking branch 'github/pr/393' into v1.1 2016-11-17 17:55:23 +01:00
Remi Collet d1290dfde0 fix test for ArgumentCountError exception with PHP 7.1 2016-11-17 15:24:54 +01:00
Remi Collet 9489d9e5aa enable 7.1 on travis 2016-11-17 15:12:24 +01:00
Fabien Villepinte 94ccb2cc3b Fix PHPDoc of \Predis\Connection\Aggregate\SentinelReplication::assertConnectionRole() 2016-09-14 17:20:55 +02:00
orvice 6c848db2a0 fix typo 2016-08-19 16:48:00 +08:00
Daniele Alessandri 6ab10b2b70 [tests] Fix preassigned slots in cluster tests. 2016-06-18 21:51:10 +02:00
Daniele Alessandri 2d4377fc81 Back to development. 2016-06-18 21:37:42 +02:00
Daniele Alessandri f0210e3888 Update CHANGELOG and bump VERSION. 2016-06-16 18:22:20 +02:00
Daniele Alessandri 5e88200ed6 Merge branch 'github/pr/344' into v1.1 2016-06-16 10:47:45 +02:00
Daniele Alessandri aed1a7bdf1 Apply same fix of 8437fbc to ClientContextInterface. 2016-06-16 10:47:01 +02:00
Daniele Alessandri 2290042680 Fix GC issues with closures for phpiredis reader handlers.
The following code, despite not being something you would do in real
world scenarios, eventually ended up generating an exception for "Too
many open files".

  for ($i = 0; $i < 10000; $i++) {
    $client = new Predis\Client();
    $client->connect();
  }

The reason was that the destructor for the connection was not invoked
by PHP as expected when the client instance went out of scope, so the
underlying stream resource were not being properly released.
Even without an actual "connect()" operation, the memory usage of PHP
kept growing until exhausting the configured value of max memory.

The source of the issue is related to the use of closures as handlers
for the phpiredis reader resource, to be more precise it seems to be
some kind of circular reference memory leak. Apparently PHP does not
like the fact that a closure, automatically bound to "$this" starting
with PHP 5.4, is stored in the reader resource which in turn is kept
referenced by "$this". This ends up the refcount not going down thus
the GC does not collect those connection objects going out of scope.
This is confirmed by the fact that this issue is not triggered when
using PHP 5.3 where the ZE does not automatically bind closures to
"$this", unless you capture "$this" with the "use()" directive (and
the usual "$that = $this" trick).

Using a static assignement instead of simply returning new closures
in "getStatusHandler()" and "getErrorHandler()" is kind of an hack
that seems to be working fine, the added value of this solution is
that we do not have to break the internal API of the three connection
backends based on ext-phpiredis.

This commit fixes #345.
2016-06-14 21:25:14 +02:00
Daniele Alessandri 295e9175ad Update CHANGELOG.
[ci skip]
2016-06-14 18:21:36 +02:00
Pascal Hofmann d92f31dc66 Don't send AUTH and/or SELECT command after connecting to sentinels 2016-06-14 17:20:08 +02:00
Felix Sandström 8437fbc84f Correcting the PHPDocs 2016-06-14 10:02:47 +02:00
Daniele Alessandri 4d58928efd [tests] Add test for Predis\Cluster\Hash\CRC16. 2016-06-13 18:57:06 +02:00
Daniele Alessandri a523cf7731 Use master for connect() when sentinel reports no slaves.
Fixes #342.
2016-06-13 15:51:23 +02:00
Daniele Alessandri 1ad0effb0a Merge remote-tracking branch 'github/pr/343' 2016-06-13 15:21:26 +02:00
Daniele Alessandri 0607d84d0c Back to development. 2016-06-13 15:20:48 +02:00
orvice a1ee7b68ef fix typos
possibile -> possible
indentify -> identify
publis ->  publish
2016-06-12 16:27:14 +08:00
41 changed files with 621 additions and 185 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
* text=auto
/tests export-ignore
/tests/PHPUnit export-ignore
/tests/Predis export-ignore
/tests/bootstrap.php export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
+2
View File
@@ -0,0 +1,2 @@
github: tillkruss
custom: "https://www.paypal.me/tillkruss"
+31
View File
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Run command '...'
2. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Versions (please complete the following information):**
- Predis: [e.g. 1.1.2]
- PHP [e.g. 8.0.0]
- Redis Server [e.g. 6.0.0]
- OS [e.g. Ubuntu 20.10]
**Code sample**
If applicable, a small snippet of code that reproduces the issue.
**Additional context**
Add any other context about the problem here.
+20
View File
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
-34
View File
@@ -1,34 +0,0 @@
<?php
$PREDIS_HEADER = <<<EOS
This file is part of the Predis package.
(c) Daniele Alessandri <suppakilla@gmail.com>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOS;
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($PREDIS_HEADER);
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
// Symfony
'-unalign_equals',
'-unalign_double_arrow',
// Contribs
'header_comment',
'ordered_use',
'phpdoc_order',
'long_array_syntax',
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__.'/bin')
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->in(__DIR__.'/examples')
);
+33
View File
@@ -0,0 +1,33 @@
<?php
$PREDIS_HEADER = <<<EOS
This file is part of the Predis package.
(c) Daniele Alessandri <suppakilla@gmail.com>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOS;
return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules(array(
'@Symfony' => true,
'header_comment' => array(
'header' => $PREDIS_HEADER,
),
'ordered_imports' => true,
'phpdoc_order' => true,
'binary_operator_spaces' => array(
'align_double_arrow' => false,
'align_equals' => false,
),
'array_syntax' => array('syntax' => 'long'),
))
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/bin')
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->in(__DIR__.'/examples')
);
+21 -9
View File
@@ -1,23 +1,35 @@
language: php
sudo: false
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
branches:
except:
- v0.5
- v0.6
- v0.6-PHP_5.2
- documentation
services: redis-server
before_install:
- docker run -d --rm -p 127.0.0.1:6379:6379 redis:3
before_script:
- composer self-update
- composer install --no-interaction --prefer-source --dev
script:
- vendor/bin/phpunit -c phpunit.xml.travisci
- travis_retry vendor/bin/phpunit -c phpunit.xml.travisci
matrix:
fast_finish: true
include:
- php: 5.3
dist: precise
services: redis-server
before_install: skip
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- php: nightly # PHP 8.0.0-dev
allow_failures:
- php: nightly
+41
View File
@@ -1,3 +1,44 @@
v1.1.3 (2020-08-18)
================================================================================
- Ensure compatibility with PHP 8.
- Moved repository from `github.com/nrk/predis` to `github.com/predis/predis`.
- __FIX__: Moved `cweagans/composer-patches` dependency to `require-dev`.
- __FIX__: Include PHPUnit `.patch` files in exports.
v1.1.2 (2020-08-11)
================================================================================
- __FIX__: pure CRC16 implementation failed to calculate the correct hash when
the input value passed to the `hash()` method is an integer (PR #450).
- __FIX__: make PHP iterator abstractions for `ZSCAN` and `HSCAN` working with
PHP 7.2 due to a breaking change, namely the removal of `each()` (PR #448).
v1.1.1 (2016-06-16)
================================================================================
- __FIX__: `password` and `database` from the global `parameters` client option
were still being applied to sentinels connections making them fail (sentinels
do not understand the `AUTH` and `SELECT` commands) (PR #346).
- __FIX__: when a sentinel instance reports no sentinel for a service, invoking
`connect()` on the redis-sentinel connection backend should fall back to the
master connection instead of failing (ISSUE #342).
- __FIX__: the two connection backends based on ext-phpiredis has some kind of
issues with the GC and the internal use of closures as reader callbacks that
prevented connections going out of scope from being properly collected and the
underlying stream or socket resources from being closed and freed. This should
not have had any actual effect in real-world scenarios due to the lifecycle of
PHP scripts, but we fixed it anyway (ISSUE #345).
v1.1.0 (2016-06-02)
================================================================================
+1 -1
View File
@@ -1,6 +1,6 @@
## Filing bug reports ##
Bugs or feature requests can be posted on the [GitHub issues](http://github.com/nrk/predis/issues)
Bugs or feature requests can be posted on the [GitHub issues](http://github.com/predis/predis/issues)
section of the project.
When reporting bugs, in addition to the obvious description of your issue you __must__ always provide
+1 -1
View File
@@ -33,7 +33,7 @@ usually something that developers prefer to customize depending on their needs a
generalized when using Redis because of the many possible access patterns for your data. This does
not mean that it is impossible to have such a feature since you can leverage the extensibility of
this library to define your own serialization-aware commands. You can find more details about how to
do that [on this issue](http://github.com/nrk/predis/issues/29#issuecomment-1202624).
do that [on this issue](http://github.com/predis/predis/issues/29#issuecomment-1202624).
### How can I force Predis to connect to Redis before sending any command? ###
+10 -16
View File
@@ -5,15 +5,12 @@
[![Latest development][ico-version-dev]][link-packagist]
[![Monthly installs][ico-downloads-monthly]][link-downloads]
[![Build status][ico-travis]][link-travis]
[![HHVM support][ico-hhvm]][link-hhvm]
[![Gitter room][ico-gitter]][link-gitter]
Flexible and feature-complete [Redis](http://redis.io) client for PHP >= 5.3 and HHVM >= 2.3.0.
Predis does not require any additional C extension by default, but it can be optionally paired with
[phpiredis](https://github.com/nrk/phpiredis) to lower the overhead of the serialization and parsing
of the [Redis RESP Protocol](http://redis.io/topics/protocol). For an __experimental__ asynchronous
implementation of the client you can refer to [Predis\Async](https://github.com/nrk/predis-async).
of the [Redis RESP Protocol](http://redis.io/topics/protocol).
More details about this project can be found on the [frequently asked questions](FAQ.md).
@@ -41,7 +38,7 @@ More details about this project can be found on the [frequently asked questions]
This library can be found on [Packagist](http://packagist.org/packages/predis/predis) for an easier
management of projects dependencies using [Composer](http://packagist.org/about-composer) or on our
[own PEAR channel](http://pear.nrk.io) for a more traditional installation using PEAR. Ultimately,
compressed archives of each release are [available on GitHub](https://github.com/nrk/predis/tags).
compressed archives of each release are [available on GitHub](https://github.com/predis/predis/releases).
### Loading the library ###
@@ -108,7 +105,7 @@ of suitable [options](http://php.net/manual/context.ssl.php) passed via the `ssl
$client = new Predis\Client([
'scheme' => 'tls',
'ssl' => ['cafile' => 'private.pem', 'verify_peer' => true],
]
]);
// Same set of parameters, but using an URI string:
$client = new Predis\Client('tls://127.0.0.1?ssl[cafile]=private.pem&ssl[verify_peer]=1');
@@ -454,7 +451,7 @@ the development server profile will be used. You can refer to [the tests README]
for more detailed information about testing Predis.
Predis uses Travis CI for continuous integration and the history for past and current builds can be
found [on its project page](http://travis-ci.org/nrk/predis).
found [on its project page](http://travis-ci.org/predis/predis).
## Other ##
@@ -462,9 +459,9 @@ found [on its project page](http://travis-ci.org/nrk/predis).
### Project related links ###
- [Source code](https://github.com/nrk/predis)
- [Wiki](https://wiki.github.com/nrk/predis)
- [Issue tracker](https://github.com/nrk/predis/issues)
- [Source code](https://github.com/predis/predis)
- [Wiki](https://github.com/predis/predis/wiki)
- [Issue tracker](https://github.com/predis/predis/issues)
- [PEAR channel](http://pear.nrk.io)
@@ -477,16 +474,13 @@ found [on its project page](http://travis-ci.org/nrk/predis).
The code for Predis is distributed under the terms of the MIT license (see [LICENSE](LICENSE)).
[ico-license]: https://img.shields.io/github/license/nrk/predis.svg?style=flat-square
[ico-license]: https://img.shields.io/github/license/predis/predis.svg?style=flat-square
[ico-version-stable]: https://img.shields.io/packagist/v/predis/predis.svg?style=flat-square
[ico-version-dev]: https://img.shields.io/packagist/vpre/predis/predis.svg?style=flat-square
[ico-downloads-monthly]: https://img.shields.io/packagist/dm/predis/predis.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/nrk/predis.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/predis/predis.svg?style=flat-square
[ico-hhvm]: https://img.shields.io/hhvm/predis/predis.svg?style=flat-square
[ico-gitter]: https://img.shields.io/gitter/room/nrk/predis.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/predis/predis
[link-travis]: https://travis-ci.org/nrk/predis
[link-travis]: https://travis-ci.org/predis/predis
[link-downloads]: https://packagist.org/packages/predis/predis/stats
[link-hhvm]: http://hhvm.h4cc.de/package/predis/predis
[link-gitter]: https://gitter.im/nrk/predis
+1 -1
View File
@@ -1 +1 @@
1.1.0
1.1.3
+1 -1
View File
@@ -59,7 +59,7 @@ spl_autoload_register(function (\$class) {
}
}
});
__HALT_COMPILER();
__halt_compiler();
EOSTUB;
}
+33 -6
View File
@@ -3,29 +3,56 @@
"type": "library",
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
"keywords": ["nosql", "redis", "predis"],
"homepage": "http://github.com/nrk/predis",
"homepage": "http://github.com/predis/predis",
"license": "MIT",
"support": {
"issues": "https://github.com/nrk/predis/issues"
"issues": "https://github.com/predis/predis/issues"
},
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla@gmail.com",
"homepage": "http://clorophilla.net"
"homepage": "http://clorophilla.net",
"role": "Creator & Maintainer"
},
{
"name": "Till Krüss",
"homepage": "https://till.im",
"role": "Maintainer"
}
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/tillkruss"
}
],
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "~4.8",
"cweagans/composer-patches": "^1.6"
},
"suggest": {
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol",
"ext-curl": "Allows access to Webdis when paired with phpiredis"
},
"autoload": {
"psr-4": {"Predis\\": "src/"}
}
"psr-4": {
"Predis\\": "src/"
}
},
"extra": {
"composer-exit-on-patch-failure": true,
"patches": {
"phpunit/phpunit-mock-objects": {
"Fix PHP 7 and 8 compatibility": "./tests/phpunit_mock_objects.patch"
},
"phpunit/phpunit": {
"Fix PHP 7 compatibility": "./tests/phpunit_php7.patch",
"Fix PHP 8 compatibility": "./tests/phpunit_php8.patch"
}
}
}
}
+4
View File
@@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/
if (PHP_SAPI !== 'cli') {
die("Example scripts are meant to be executed locally via CLI.");
}
require __DIR__.'/../autoload.php';
function redis_version($info)
+1 -1
View File
@@ -10,7 +10,7 @@ name = "Predis"
desc = "Flexible and feature-complete Redis client for PHP and HHVM"
homepage = "http://github.com/nrk/predis"
license = "MIT"
version = "1.1.0"
version = "1.1.3"
stability = "stable"
channel = "pear.nrk.io"
+3 -3
View File
@@ -40,7 +40,7 @@ use Predis\Transaction\MultiExec as MultiExecTransaction;
*/
class Client implements ClientInterface, \IteratorAggregate
{
const VERSION = '1.1.0';
const VERSION = '1.1.3';
protected $connection;
protected $options;
@@ -278,7 +278,7 @@ class Client implements ClientInterface, \IteratorAggregate
* applying any prefix to keys or throwing exceptions on Redis errors even
* regardless of client options.
*
* It is possibile to indentify Redis error responses from normal responses
* It is possible to identify Redis error responses from normal responses
* using the second optional argument which is populated by reference.
*
* @param array $arguments Command arguments as defined by the command signature.
@@ -481,7 +481,7 @@ class Client implements ClientInterface, \IteratorAggregate
}
/**
* Creates a new publis/subscribe context and returns it, or starts its loop
* Creates a new publish/subscribe context and returns it, or starts its loop
* inside the optionally provided callable object.
*
* @param mixed ... Array of options, a callable for execution, or both.
+14 -14
View File
@@ -16,7 +16,7 @@ use Predis\Command\CommandInterface;
/**
* Interface defining a client-side context such as a pipeline or transaction.
*
* @method $this del(array $keys)
* @method $this del(array|string $keys)
* @method $this dump($key)
* @method $this exists($key)
* @method $this expire($key, $seconds)
@@ -38,7 +38,7 @@ use Predis\Command\CommandInterface;
* @method $this append($key, $value)
* @method $this bitcount($key, $start = null, $end = null)
* @method $this bitop($operation, $destkey, $key)
* @method $this bitfield($key, ...)
* @method $this bitfield($key, $subcommand, ...$subcommandArg)
* @method $this decr($key)
* @method $this decrby($key, $decrement)
* @method $this get($key)
@@ -73,8 +73,8 @@ use Predis\Command\CommandInterface;
* @method $this hsetnx($key, $field, $value)
* @method $this hvals($key)
* @method $this hstrlen($key, $field)
* @method $this blpop(array $keys, $timeout)
* @method $this brpop(array $keys, $timeout)
* @method $this blpop(array|string $keys, $timeout)
* @method $this brpop(array|string $keys, $timeout)
* @method $this brpoplpush($source, $destination, $timeout)
* @method $this lindex($key, $index)
* @method $this linsert($key, $whence, $pivot, $value)
@@ -92,10 +92,10 @@ use Predis\Command\CommandInterface;
* @method $this rpushx($key, $value)
* @method $this sadd($key, array $members)
* @method $this scard($key)
* @method $this sdiff(array $keys)
* @method $this sdiffstore($destination, array $keys)
* @method $this sinter(array $keys)
* @method $this sinterstore($destination, array $keys)
* @method $this sdiff(array|string $keys)
* @method $this sdiffstore($destination, array|string $keys)
* @method $this sinter(array|string $keys)
* @method $this sinterstore($destination, array|string $keys)
* @method $this sismember($key, $member)
* @method $this smembers($key)
* @method $this smove($source, $destination, $member)
@@ -103,13 +103,13 @@ use Predis\Command\CommandInterface;
* @method $this srandmember($key, $count = null)
* @method $this srem($key, $member)
* @method $this sscan($key, $cursor, array $options = null)
* @method $this sunion(array $keys)
* @method $this sunionstore($destination, array $keys)
* @method $this sunion(array|string $keys)
* @method $this sunionstore($destination, array|string $keys)
* @method $this zadd($key, array $membersAndScoresDictionary)
* @method $this zcard($key)
* @method $this zcount($key, $min, $max)
* @method $this zincrby($key, $increment, $member)
* @method $this zinterstore($destination, array $keys, array $options = null)
* @method $this zinterstore($destination, array|string $keys, array $options = null)
* @method $this zrange($key, $start, $stop, array $options = null)
* @method $this zrangebyscore($key, $min, $max, array $options = null)
* @method $this zrank($key, $member)
@@ -119,7 +119,7 @@ use Predis\Command\CommandInterface;
* @method $this zrevrange($key, $start, $stop, array $options = null)
* @method $this zrevrangebyscore($key, $min, $max, array $options = null)
* @method $this zrevrank($key, $member)
* @method $this zunionstore($destination, array $keys, array $options = null)
* @method $this zunionstore($destination, array|string $keys, array $options = null)
* @method $this zscore($key, $member)
* @method $this zscan($key, $cursor, array $options = null)
* @method $this zrangebylex($key, $start, $stop, array $options = null)
@@ -127,8 +127,8 @@ use Predis\Command\CommandInterface;
* @method $this zremrangebylex($key, $min, $max)
* @method $this zlexcount($key, $min, $max)
* @method $this pfadd($key, array $elements)
* @method $this pfmerge($destinationKey, array $sourceKeys)
* @method $this pfcount(array $keys)
* @method $this pfmerge($destinationKey, array|string $sourceKeys)
* @method $this pfcount(array|string $keys)
* @method $this pubsub($subcommand, $argument)
* @method $this publish($channel, $message)
* @method $this discard()
+15 -15
View File
@@ -24,7 +24,7 @@ use Predis\Profile\ProfileInterface;
* and more friendly interface to ease programming which is described in the
* following list of methods:
*
* @method int del(array $keys)
* @method int del(array|string $keys)
* @method string dump($key)
* @method int exists($key)
* @method int expire($key, $seconds)
@@ -46,7 +46,7 @@ use Predis\Profile\ProfileInterface;
* @method int append($key, $value)
* @method int bitcount($key, $start = null, $end = null)
* @method int bitop($operation, $destkey, $key)
* @method array bitfield($key, ...)
* @method array bitfield($key, $subcommand, ...$subcommandArg)
* @method int decr($key)
* @method int decrby($key, $decrement)
* @method string get($key)
@@ -81,8 +81,8 @@ use Predis\Profile\ProfileInterface;
* @method int hsetnx($key, $field, $value)
* @method array hvals($key)
* @method int hstrlen($key, $field)
* @method array blpop(array $keys, $timeout)
* @method array brpop(array $keys, $timeout)
* @method array blpop(array|string $keys, $timeout)
* @method array brpop(array|string $keys, $timeout)
* @method array brpoplpush($source, $destination, $timeout)
* @method string lindex($key, $index)
* @method int linsert($key, $whence, $pivot, $value)
@@ -100,24 +100,24 @@ use Predis\Profile\ProfileInterface;
* @method int rpushx($key, $value)
* @method int sadd($key, array $members)
* @method int scard($key)
* @method array sdiff(array $keys)
* @method int sdiffstore($destination, array $keys)
* @method array sinter(array $keys)
* @method int sinterstore($destination, array $keys)
* @method array sdiff(array|string $keys)
* @method int sdiffstore($destination, array|string $keys)
* @method array sinter(array|string $keys)
* @method int sinterstore($destination, array|string $keys)
* @method int sismember($key, $member)
* @method array smembers($key)
* @method int smove($source, $destination, $member)
* @method string spop($key, $count = null)
* @method array spop($key, $count = null)
* @method string srandmember($key, $count = null)
* @method int srem($key, $member)
* @method array sscan($key, $cursor, array $options = null)
* @method array sunion(array $keys)
* @method int sunionstore($destination, array $keys)
* @method array sunion(array|string $keys)
* @method int sunionstore($destination, array|string $keys)
* @method int zadd($key, array $membersAndScoresDictionary)
* @method int zcard($key)
* @method string zcount($key, $min, $max)
* @method string zincrby($key, $increment, $member)
* @method int zinterstore($destination, array $keys, array $options = null)
* @method int zinterstore($destination, array|string $keys, array $options = null)
* @method array zrange($key, $start, $stop, array $options = null)
* @method array zrangebyscore($key, $min, $max, array $options = null)
* @method int zrank($key, $member)
@@ -127,7 +127,7 @@ use Predis\Profile\ProfileInterface;
* @method array zrevrange($key, $start, $stop, array $options = null)
* @method array zrevrangebyscore($key, $max, $min, array $options = null)
* @method int zrevrank($key, $member)
* @method int zunionstore($destination, array $keys, array $options = null)
* @method int zunionstore($destination, array|string $keys, array $options = null)
* @method string zscore($key, $member)
* @method array zscan($key, $cursor, array $options = null)
* @method array zrangebylex($key, $start, $stop, array $options = null)
@@ -135,8 +135,8 @@ use Predis\Profile\ProfileInterface;
* @method int zremrangebylex($key, $min, $max)
* @method int zlexcount($key, $min, $max)
* @method int pfadd($key, array $elements)
* @method mixed pfmerge($destinationKey, array $sourceKeys)
* @method int pfcount(array $keys)
* @method mixed pfmerge($destinationKey, array|string $sourceKeys)
* @method int pfcount(array|string $keys)
* @method mixed pubsub($subcommand, $argument)
* @method int publish($channel, $message)
* @method mixed discard()
+2
View File
@@ -61,6 +61,8 @@ class CRC16 implements HashGeneratorInterface
// CRC-CCITT-16 algorithm
$crc = 0;
$CCITT_16 = self::$CCITT_16;
$value = (string) $value;
$strlen = strlen($value);
for ($i = 0; $i < $strlen; ++$i) {
+3 -5
View File
@@ -50,11 +50,9 @@ class HashKey extends CursorBasedIterator
*/
protected function extractNext()
{
if ($kv = each($this->elements)) {
$this->position = $kv[0];
$this->current = $kv[1];
$this->position = key($this->elements);
$this->current = current($this->elements);
unset($this->elements[$this->position]);
}
unset($this->elements[$this->position]);
}
}
+3 -5
View File
@@ -50,11 +50,9 @@ class SortedSetKey extends CursorBasedIterator
*/
protected function extractNext()
{
if ($kv = each($this->elements)) {
$this->position = $kv[0];
$this->current = $kv[1];
$this->position = key($this->elements);
$this->current = current($this->elements);
unset($this->elements[$this->position]);
}
unset($this->elements[$this->position]);
}
}
+13 -7
View File
@@ -11,16 +11,22 @@
namespace Predis\Configuration;
use Predis\Command\Processor\ProcessorInterface;
use Predis\Connection\Aggregate\ClusterInterface;
use Predis\Connection\Aggregate\ReplicationInterface;
use Predis\Connection\FactoryInterface;
use Predis\Profile\ProfileInterface;
/**
* Interface defining a container for client options.
*
* @property-read mixed aggregate Custom connection aggregator.
* @property-read mixed cluster Aggregate connection for clustering.
* @property-read mixed connections Connection factory.
* @property-read mixed exceptions Toggles exceptions in client for -ERR responses.
* @property-read mixed prefix Key prefixing strategy using the given prefix.
* @property-read mixed profile Server profile.
* @property-read mixed replication Aggregate connection for replication.
* @property-read callable $aggregate Custom connection aggregator.
* @property-read ClusterInterface $cluster Aggregate connection for clustering.
* @property-read FactoryInterface $connections Connection factory.
* @property-read bool $exceptions Toggles exceptions in client for -ERR responses.
* @property-read ProcessorInterface $prefix Key prefixing strategy using the given prefix.
* @property-read ProfileInterface $profile Server profile.
* @property-read ReplicationInterface $replication Aggregate connection for replication.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
@@ -239,9 +239,10 @@ class SentinelReplication implements ReplicationInterface
}
if (is_array($parameters)) {
// We unset "password" and "database" from user-supplied parameters
// as they are not needed when connecting to sentinels.
unset($parameters['database'], $parameters['password']);
// We explicitly set "database" and "password" to null,
// so that no AUTH and SELECT command is send to the sentinels.
$parameters['database'] = null;
$parameters['password'] = null;
if (!isset($parameters['timeout'])) {
$parameters['timeout'] = $this->sentinelTimeout;
@@ -514,8 +515,10 @@ class SentinelReplication implements ReplicationInterface
/**
* Asserts that the specified connection matches an expected role.
*
* @param NodeConnectionInterface $sentinel Connection to a redis server.
* @param string $role Expected role of the server ("master", "slave" or "sentinel").
* @param NodeConnectionInterface $connection Connection to a redis server.
* @param string $role Expected role of the server ("master", "slave" or "sentinel").
*
* @throws RoleException
*/
protected function assertConnectionRole(NodeConnectionInterface $connection, $role)
{
@@ -617,7 +620,9 @@ class SentinelReplication implements ReplicationInterface
public function connect()
{
if (!$this->current) {
$this->current = $this->pickSlave();
if (!$this->current = $this->pickSlave()) {
$this->current = $this->getMaster();
}
}
$this->current->connect();
+19 -7
View File
@@ -143,11 +143,17 @@ class PhpiredisSocketConnection extends AbstractConnection
*
* @return \Closure
*/
private function getStatusHandler()
protected function getStatusHandler()
{
return function ($payload) {
return StatusResponse::get($payload);
};
static $statusHandler;
if (!$statusHandler) {
$statusHandler = function ($payload) {
return StatusResponse::get($payload);
};
}
return $statusHandler;
}
/**
@@ -157,9 +163,15 @@ class PhpiredisSocketConnection extends AbstractConnection
*/
protected function getErrorHandler()
{
return function ($payload) {
return new ErrorResponse($payload);
};
static $errorHandler;
if (!$errorHandler) {
$errorHandler = function ($errorMessage) {
return new ErrorResponse($errorMessage);
};
}
return $errorHandler;
}
/**
+18 -6
View File
@@ -160,9 +160,15 @@ class PhpiredisStreamConnection extends StreamConnection
*/
protected function getStatusHandler()
{
return function ($payload) {
return StatusResponse::get($payload);
};
static $statusHandler;
if (!$statusHandler) {
$statusHandler = function ($payload) {
return StatusResponse::get($payload);
};
}
return $statusHandler;
}
/**
@@ -172,9 +178,15 @@ class PhpiredisStreamConnection extends StreamConnection
*/
protected function getErrorHandler()
{
return function ($errorMessage) {
return new ErrorResponse($errorMessage);
};
static $errorHandler;
if (!$errorHandler) {
$errorHandler = function ($errorMessage) {
return new ErrorResponse($errorMessage);
};
}
return $errorHandler;
}
/**
+18 -6
View File
@@ -163,9 +163,15 @@ class WebdisConnection implements NodeConnectionInterface
*/
protected function getStatusHandler()
{
return function ($payload) {
return StatusResponse::get($payload);
};
static $statusHandler;
if (!$statusHandler) {
$statusHandler = function ($payload) {
return StatusResponse::get($payload);
};
}
return $statusHandler;
}
/**
@@ -175,9 +181,15 @@ class WebdisConnection implements NodeConnectionInterface
*/
protected function getErrorHandler()
{
return function ($payload) {
return new ErrorResponse($payload);
};
static $errorHandler;
if (!$errorHandler) {
$errorHandler = function ($errorMessage) {
return new ErrorResponse($errorMessage);
};
}
return $errorHandler;
}
/**
+50
View File
@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Cluster\Hash;
use PredisTestCase;
/**
*
*/
class CRC16Test extends PredisTestCase
{
/**
* @group disconnected
*/
public function testHashGeneration()
{
$crc16 = new CRC16();
$this->assertSame(58359, $crc16->hash('key:000'));
$this->assertSame(62422, $crc16->hash('key:001'));
$this->assertSame(50101, $crc16->hash('key:002'));
$this->assertSame(54164, $crc16->hash('key:003'));
$this->assertSame(41843, $crc16->hash('key:004'));
$this->assertSame(45906, $crc16->hash('key:005'));
$this->assertSame(33585, $crc16->hash('key:006'));
$this->assertSame(37648, $crc16->hash('key:007'));
$this->assertSame(25343, $crc16->hash('key:008'));
$this->assertSame(29406, $crc16->hash('key:009'));
}
/**
* @group disconnected
*/
public function testHashGenerationWithIntegerValues()
{
$crc16 = new CRC16();
$this->assertSame(13907, $crc16->hash(0));
$this->assertSame(55177, $crc16->hash(1234));
}
}
@@ -57,8 +57,8 @@ class HashKeyTest extends PredisTestCase
}
/**
* @link https://github.com/nrk/predis/pull/330
* @link https://github.com/nrk/predis/issues/331
* @see https://github.com/predis/predis/pull/330
* @see https://github.com/predis/predis/issues/331
* @group disconnected
*/
public function testIterationWithIntegerFields()
@@ -57,7 +57,7 @@ class SortedSetKeyTest extends PredisTestCase
}
/**
* @link https://github.com/nrk/predis/issues/216
* @see https://github.com/predis/predis/issues/216
* @group disconnected
*/
public function testIterationWithIntegerMembers()
+14 -2
View File
@@ -71,12 +71,24 @@ class ConnectionSelectTest extends PredisCommandTestCase
/**
* @group connected
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessage ERR invalid DB index
* @expectedExceptionMessageRegExp /ERR.*DB index/
*/
public function testThrowsExceptionOnUnexpectedDatabase()
public function testThrowsExceptionOnUnexpectedDatabaseRange()
{
$redis = $this->getClient();
$redis->select(100000000);
}
/**
* @group connected
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessage ERR invalid DB index
*/
public function testThrowsExceptionOnUnexpectedDatabaseName()
{
$redis = $this->getClient();
$redis->select('x');
}
}
@@ -145,7 +145,7 @@ class PubSubSubscribeByPatternTest extends PredisCommandTestCase
/**
* @group connected
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessageRegExp /ERR only .* allowed in this context/
* @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/
*/
public function testCannotSendOtherCommandsAfterPsubscribe()
{
+1 -1
View File
@@ -145,7 +145,7 @@ class PubSubSubscribeTest extends PredisCommandTestCase
/**
* @group connected
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessageRegExp /ERR only .* allowed in this context/
* @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/
*/
public function testCannotSendOtherCommandsAfterSubscribe()
{
+20 -1
View File
@@ -74,10 +74,29 @@ class RawCommandTest extends PredisTestCase
* argument is missing, PHP emits an E_WARNING.
*
* @group disconnected
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testPHPWarningOnMissingCommandIDWithStaticCreate()
{
if (version_compare(PHP_VERSION, "7.1", '>')) {
$this->markTestSkipped('only for PHP < 7.1');
}
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
RawCommand::create();
}
/**
* The signature of RawCommand::create() requires one argument which is the
* ID of the command (other arguments are fetched dinamically). If the first
* argument is missing, PHP 7.1 throw an exception
*
* @group disconnected
*/
public function testPHPWarningOnMissingCommandIDWithStaticCreate71()
{
if (version_compare(PHP_VERSION, "7.1", '<')) {
$this->markTestSkipped('only for PHP > 7.1');
}
$this->setExpectedException('ArgumentCountError');
RawCommand::create();
}
@@ -76,7 +76,7 @@ class StringIncrementByFloatTest extends PredisCommandTestCase
$redis->set('foo', 2);
// We use round() to avoid errors on some platforms, see the following
// issue https://github.com/nrk/predis/issues/220 for reference.
// issue https://github.com/predis/predis/issues/220 for reference.
$this->assertEquals(22.123, $redis->incrbyfloat('foo', 20.123));
$this->assertEquals(10, round($redis->incrbyfloat('foo', -12.123), 5));
$this->assertEquals(-100.01, round($redis->incrbyfloat('foo', -110.01), 5));
@@ -245,8 +245,8 @@ class RedisClusterTest extends PredisTestCase
public function testGetIteratorReturnsConnectionsMappedInSlotsMapWhenUseClusterSlotsIsDisabled()
{
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10922');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10923-16383');
$connection4 = $this->getMockConnection('tcp://127.0.0.1:6384');
$cluster = new RedisCluster(new Connection\Factory());
@@ -274,8 +274,8 @@ class RedisClusterTest extends PredisTestCase
{
$slotsmap = array(
array(0, 5460, array('127.0.0.1', 6381), array()),
array(5461, 10921, array('127.0.0.1', 6383), array()),
array(10922, 16383, array('127.0.0.1', 6384), array()),
array(5461, 10922, array('127.0.0.1', 6383), array()),
array(10923, 16383, array('127.0.0.1', 6384), array()),
);
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460');
@@ -286,7 +286,7 @@ class RedisClusterTest extends PredisTestCase
))
->will($this->returnValue($slotsmap));
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10922');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383');
$connection4 = $this->getMockConnection('tcp://127.0.0.1:6384');
@@ -398,8 +398,8 @@ class RedisClusterTest extends PredisTestCase
public function testCanAssignConnectionsToRangeOfSlotsFromParameters()
{
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-5460');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-10921');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10922-16383');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-10922');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10923-16383');
$cluster = new RedisCluster(new Connection\Factory());
$cluster->add($connection1);
@@ -410,8 +410,8 @@ class RedisClusterTest extends PredisTestCase
$expectedMap = array_merge(
array_fill(0, 5461, '127.0.0.1:6379'),
array_fill(5460, 5461, '127.0.0.1:6380'),
array_fill(10921, 5462, '127.0.0.1:6381')
array_fill(5460, 5462, '127.0.0.1:6380'),
array_fill(10923, 5461, '127.0.0.1:6381')
);
$actualMap = $cluster->getSlotsMap();
@@ -426,8 +426,8 @@ class RedisClusterTest extends PredisTestCase
public function testCanAssignConnectionsToSingleSlotOrRangesOfSlotsFromParameters()
{
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-5460,5500-5600,11000');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-5499,5600-10921');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10922-10999,11001-16383');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-5499,5600-10922');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10923-10999,11001-16383');
$cluster = new RedisCluster(new Connection\Factory());
$cluster->add($connection1);
@@ -440,8 +440,8 @@ class RedisClusterTest extends PredisTestCase
array_fill(0, 5461, '127.0.0.1:6379'),
array_fill(5460, 39, '127.0.0.1:6380'),
array_fill(5499, 101, '127.0.0.1:6379'),
array_fill(5599, 5321, '127.0.0.1:6380'),
array_fill(10921, 78, '127.0.0.1:6381'),
array_fill(5599, 5322, '127.0.0.1:6380'),
array_fill(10923, 77, '127.0.0.1:6381'),
array_fill(11000, 1, '127.0.0.1:6379'),
array_fill(11000, 5383, '127.0.0.1:6381')
);
@@ -555,8 +555,8 @@ class RedisClusterTest extends PredisTestCase
{
$slotsmap = array(
array(0, 5460, array('127.0.0.1', 9381), array()),
array(5461, 10921, array('127.0.0.1', 6382), array()),
array(10922, 16383, array('127.0.0.1', 6383), array()),
array(5461, 10922, array('127.0.0.1', 6382), array()),
array(10923, 16383, array('127.0.0.1', 6383), array()),
);
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460');
@@ -569,7 +569,7 @@ class RedisClusterTest extends PredisTestCase
new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]')
));
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10922');
$connection2->expects($this->any())
->method('executeCommand')
->with($this->isRedisCommand(
@@ -577,7 +577,7 @@ class RedisClusterTest extends PredisTestCase
))
->will($this->returnValue($slotsmap));
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10923-16383');
$connection3->expects($this->any())
->method('executeCommand')
->with($this->isRedisCommand(
@@ -720,8 +720,8 @@ class RedisClusterTest extends PredisTestCase
{
$slotsmap = array(
array(0, 5460, array('127.0.0.1', 9381), array()),
array(5461, 10921, array('127.0.0.1', 6382), array()),
array(10922, 16383, array('127.0.0.1', 6383), array()),
array(5461, 10922, array('127.0.0.1', 6382), array()),
array(10923, 16383, array('127.0.0.1', 6383), array()),
);
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460');
@@ -734,7 +734,7 @@ class RedisClusterTest extends PredisTestCase
new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]')
));
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10922');
$connection2->expects($this->once())
->method('executeCommand')
->with($this->isRedisCommand(
@@ -744,7 +744,7 @@ class RedisClusterTest extends PredisTestCase
new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6383]')
));
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10923-16383');
$connection3->expects($this->once())
->method('executeCommand')
->with($this->isRedisCommand(
@@ -777,8 +777,8 @@ class RedisClusterTest extends PredisTestCase
{
$slotsmap = array(
array(0, 5460, array('127.0.0.1', 9381), array()),
array(5461, 10921, array('127.0.0.1', 6382), array()),
array(10922, 16383, array('127.0.0.1', 6383), array()),
array(5461, 10922, array('127.0.0.1', 6382), array()),
array(10923, 16383, array('127.0.0.1', 6383), array()),
);
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460');
@@ -791,7 +791,7 @@ class RedisClusterTest extends PredisTestCase
new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]')
));
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10922');
$connection2->expects($this->any())
->method('executeCommand')
->with($this->isRedisCommand(
@@ -801,7 +801,7 @@ class RedisClusterTest extends PredisTestCase
new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6382]')
));
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10923-16383');
$connection3->expects($this->never())
->method('executeCommand');
@@ -1142,9 +1142,9 @@ class RedisClusterTest extends PredisTestCase
*/
public function testCanBeSerialized()
{
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-1364');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=1365-2729');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=2730-4095');
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6379?slots=0-5460');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6380?slots=5461-10922');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10923-16383');
$cluster = new RedisCluster(new Connection\Factory());
$cluster->add($connection1);
@@ -44,8 +44,7 @@ class SentinelReplicationTest extends PredisTestCase
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
$this->assertArrayNotHasKey('password', $parameters);
$this->assertArrayNotHasKey('database', $parameters);
$this->assertArraySubset(array('database' => null, 'password' => null), $parameters);
}
/**
@@ -552,6 +551,48 @@ class SentinelReplicationTest extends PredisTestCase
$replication->connect();
}
/**
* @group disconnected
*/
public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToMasterIfStillEmpty()
{
$sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
$sentinel1->expects($this->at(0))
->method('executeCommand')
->with($this->isRedisCommand(
'SENTINEL', array('slaves', 'svc')
))
->will($this->returnValue(
array()
));
$sentinel1->expects($this->at(1))
->method('executeCommand')
->with($this->isRedisCommand(
'SENTINEL', array('get-master-addr-by-name', 'svc')
))
->will($this->returnValue(
array('127.0.0.1', '6381')
));
$master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
$master->expects($this->once())
->method('connect');
$factory = $this->getMock('Predis\Connection\FactoryInterface');
$factory->expects($this->once())
->method('create')
->with(array(
'host' => '127.0.0.1',
'port' => '6381',
'alias' => 'master',
))
->will($this->returnValue($master));
$replication = $this->getReplicationConnection('svc', array($sentinel1), $factory);
$replication->connect();
}
/**
* @group disconnected
*/
+1 -1
View File
@@ -69,7 +69,7 @@ $ phpunit --exclude-group slow
### Testing Redis commands ###
We also provide an helper script in the `bin` directory that can be used to automatically generate a
file with the scheleton of a test case to test a Redis command by specifying the name of the class
file with the skeleton of a test case to test a Redis command by specifying the name of the class
in the `Predis\Command` namespace (only classes in this namespace are considered valid). For example
to generate a test case for `SET` (represented by the `Predis\Command\StringSet` class):
+38
View File
@@ -0,0 +1,38 @@
diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php
index 3df3abb..fc76d5d 100644
--- a/src/Framework/MockObject/Generator.php
+++ b/src/Framework/MockObject/Generator.php
@@ -1031,16 +1031,29 @@ protected function getMethodParameters(ReflectionMethod $method, $forCall = fals
$typeDeclaration = '';
if (!$forCall) {
+ if (PHP_VERSION_ID >= 80000) {
+ $isArray = $parameter->getType() && $parameter->getType()->getName() === 'array';
+ $isCallable = $parameter->getType() && $parameter->getType()->getName() === 'callable';
+ } else {
+ $isArray = $parameter->isArray();
+ $isCallable = version_compare(PHP_VERSION, '5.4.0', '>=') ? $parameter->isCallable() : false;
+ }
+
if ($this->hasType($parameter)) {
- $typeDeclaration = (string) $parameter->getType() . ' ';
- } elseif ($parameter->isArray()) {
+ $type = $parameter->getType();
+ $typeDeclaration = (PHP_VERSION_ID >= 70100 ? $type->getName() : (string) $type) . ' ';
+ } elseif ($isArray) {
$typeDeclaration = 'array ';
} elseif ((defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.4.0', '>='))
- && $parameter->isCallable()) {
+ && $isCallable) {
$typeDeclaration = 'callable ';
} else {
try {
- $class = $parameter->getClass();
+ if (PHP_VERSION_ID >= 80000) {
+ $class = $parameter->getType();
+ } else {
+ $class = $parameter->getClass();
+ }
} catch (ReflectionException $e) {
throw new PHPUnit_Framework_MockObject_RuntimeException(
sprintf(
+60
View File
@@ -0,0 +1,60 @@
diff --git a/src/Util/Getopt.php b/src/Util/Getopt.php
index ba21be3..96931a3 100644
--- a/src/Util/Getopt.php
+++ b/src/Util/Getopt.php
@@ -35,7 +35,15 @@ class PHPUnit_Util_Getopt
reset($args);
array_map('trim', $args);
- while (list($i, $arg) = each($args)) {
+ while (true) {
+ $arg = current($args);
+ $i = key($args);
+ next($args);
+
+ if ($arg === false) {
+ break;
+ }
+
if ($arg == '') {
continue;
}
@@ -94,11 +102,14 @@ class PHPUnit_Util_Getopt
if ($i + 1 < $argLen) {
$opts[] = array($opt, substr($arg, $i + 1));
break;
- } elseif (list(, $opt_arg) = each($args)) {
} else {
- throw new PHPUnit_Framework_Exception(
- "option requires an argument -- $opt"
- );
+ $opt_arg = current($args);
+ next($args);
+ if ($opt_arg === false) {
+ throw new PHPUnit_Framework_Exception(
+ "option requires an argument -- $opt"
+ );
+ }
}
}
}
@@ -139,11 +150,14 @@ class PHPUnit_Util_Getopt
if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
- if (!strlen($opt_arg) &&
- !(list(, $opt_arg) = each($args))) {
- throw new PHPUnit_Framework_Exception(
- "option --$opt requires an argument"
- );
+ if (!strlen($opt_arg)) {
+ $opt_arg = current($args);
+ next($args);
+ if ($opt_arg === false) {
+ throw new PHPUnit_Framework_Exception(
+ "option --$opt requires an argument"
+ );
+ }
}
}
} elseif ($opt_arg) {
+39
View File
@@ -0,0 +1,39 @@
diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php
index 638f42513..b4c7d3a5e 100644
--- a/src/Framework/TestCase.php
+++ b/src/Framework/TestCase.php
@@ -905,7 +905,7 @@ protected function runTest()
try {
$testResult = $method->invokeArgs(
$this,
- array_merge($this->data, $this->dependencyInput)
+ array_values(array_merge($this->data, $this->dependencyInput))
);
} catch (Throwable $_e) {
$e = $_e;
diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php
index 5c1041608..b2f7a7bd0 100644
--- a/src/Util/Configuration.php
+++ b/src/Util/Configuration.php
@@ -162,7 +162,7 @@ protected function __construct($filename)
/**
* @since Method available since Release 3.4.0
*/
- final private function __clone()
+ private function __clone()
{
}
diff --git a/src/Util/PHP/Template/TestCaseMethod.tpl.dist b/src/Util/PHP/Template/TestCaseMethod.tpl.dist
index b48f354cd..d59cdeea7 100644
--- a/src/Util/PHP/Template/TestCaseMethod.tpl.dist
+++ b/src/Util/PHP/Template/TestCaseMethod.tpl.dist
@@ -78,7 +78,7 @@ if ('' !== $configurationFilePath) {
unset($configuration);
}
-function __phpunit_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
+function __phpunit_error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
{
return true;
}