240 Commits

Author SHA1 Message Date
michael-grunder
b808cc60ed Update tests so they can run in php-cgi.
This probably isn't a very common scenerio since we've never had someone
ask it in a decade, but it was very simple to get them working.

Primarily we just needed to test for `STDTOUT`/`STDERR` and use
`__DIR__` instead of `$_SERVER['PHP_SELF']`.

Fixes #2507
2024-06-17 11:46:44 -07:00
michael-grunder
78b70ca8f4 More test refactoring.
* Switch remaining old-style PHP 5.4 `Array(...)` declarations to `[...]`
* Update variable names getting rid hungarian notation prefixes (e.g.
  `str_`, `i_`, etc).
* Allow cluster seeds to be passed on the command-line instead of soley
  relying on either a node environment variable or our
  tests/nodes/nodemap file.  This should make it easier to run ad-hoc
  cluster tests by specifying just a single seed.
* Add some diagnostics for when we can't find a suitable cluster to run
  our tests against indicating exactly where we looked for the env var
  and node file.
* Refactor RedisArray tests to use our newer TestSuite assertions.
* Allow `RedisArray` ports to be specified on the command-line as well.
* Various formatting fixes.
* More robust KeyDB detection.
2024-05-29 23:02:29 -07:00
michael-grunder
5f6ce414c3 Update tests to allow users to use a custom class.
Add a mechanism that allows users to specify an arbitrary class name, in
combination with a search path so that PhpRedis unit tests can be run
against a different client.

Additionally, this commit allows multiple classes to be invoked in one
test execution either by passing multiple `--class` arguments, or a
class argument with a comma separated value.
2023-09-19 11:57:49 -07:00
Michael Grunder
a311cc4ec3 Support for Redis 6 ACLs (#1791)
Add support for Redis 6 ACLs in the `Redis`, `RedisCluster`, and `RedisArray` classes.

On a related note, it adds a mechanism for users to customize how we generate persistent connection IDs such that they can be grouped in different ways depending on the specific use case required (e.g. it would allow connections to be grouped by username, or by user-defined persistent_id, or both).
2020-06-24 17:00:01 -07:00
Michael Grunder
201a975999 Make unit test authentication configurable (#1748)
Right now cloning the repo and running unit tests will all fail if the
Redis/RedisCluster instances aren't configured with the password
'phpredis'.

This commit simply makes authentication during the tests optional via a
command-line argument.
2020-04-30 21:22:40 -07:00
Pavlo Yatsukhnenko
c94e28f1eb Add RedisSentinel class and tests 2020-02-06 14:14:46 -08:00
michael-grunder
9440f05e19 Switch everything to new array syntax 2019-02-09 14:12:52 -08:00
michael-grunder
9ac9845d32 Use old style array declaration 2017-03-25 16:19:11 -07:00
michael-grunder
4aff3f9c00 Make RedisArray tests exit with a nonzero exit code on failure 2017-03-25 14:28:29 -07:00
Remi Collet
28be4a8d28 display integer size in test suite output 2016-12-22 11:55:21 +01:00
Remi Collet
ccd11e869b disply PHP version in test output 2016-12-21 09:59:25 +01:00
michael-grunder
68cf720ff6 Skip GEO* tests if version < 3.2.0 2016-06-10 11:13:03 -07:00
michael-grunder
3012052849 More IPv6 additions
* Modified RedisArray to support IPv6
* Updated general test suite to take an override host
* Updated make-cluster.sh to take an override host
2016-02-12 18:10:50 -08:00
michael-grunder
08ecec92a3 Unit test suite improvements and cluster failover test
* Added a test specifically for RedisCluster to test slave failover
  settings.
* Added an option to specifically disable colorization, as well as
  a mechanism to determine if the output is being piped, such that
  we can turn colorization off in that case as well.
2015-05-05 15:18:02 -07:00
michael-grunder
97c9edc3aa Sorted a memory leak in RedisArray and retabbed unit tests 2015-05-05 15:18:01 -07:00
michael-grunder
469e8e9377 Various cluster fixes and Unit test updates
* Updated the unit test suite to print each unit test method name we're
  running as we do so, and also with fancy colors :-)
* Added functionality to handle failed transactions, where Redis will send
  us a multi bulk length of -1.  This can happen because of an EXECABORT
  error, or because a watched key was modified during the transaction
* Initialize serialized return value to NULL to avoid segfault
* use strtol not atoi in our long response handler, to handle large values
* Fixed our return value in multi responses
* Fiexed type() command as cluster doesn't still have the '+' prefix when
  checking for what TYPE returns
* Exists should return a BOOLEAN not 1/0
* Fixed sRandMember to work in the context of a MULTI block
* Use "LINDEX" not "LGET" as "LGET" isn't a valid Redis command
* Properly set our slot for the PFCOUNT command
* Many unit test changes such that Redis and RedisCluster are happy using
  mostly the same ones.
2015-05-05 15:16:49 -07:00
michael-grunder
0b269cbb72 More RedisCluster fixes
* Properly handle single array as well as variadic arguments for
  things like RedisCluster::del
* Wrapping keys in {} such that Redis and RedisCluster tests can
  use the same methods (avoiding CROSSSLOT).
* Fixed a double-free scenerio in redis_array_impl.c
2015-05-05 15:16:49 -07:00
michael-grunder
0a36429ee7 Add simple options to limit which tests are run 2015-05-05 15:11:46 -07:00
michael-grunder
79cb6a8905 Initial commit reworking unit tests
This commit reworks the unit tests such that all three classes
(Redis, RedisArray, and RedisCluster) can be tested using the
TestRedis.php script.

Now, when running TestRedis.php an option can be passed for which
part of phpredis we would like to test (defaults to Redis).
2015-05-05 15:07:43 -07:00
michael-grunder
2336477e10 Allow for pfcount to take multiple keys
When first creating the pfCount function, I simply allowed for one
string value for the key.  Either Redis changed since then, or I
just missed it initially, but the PFCOUNT command can take one or
more keys.

This change doesn't break the API (in case anyone is using it under
develop now) as it can still take a single string argument, or can
take an array.
2014-12-17 17:42:08 -08:00
michael-grunder
590c753bc1 Capture error for multibulk responses
Addresses #540
2014-12-17 12:35:07 -08:00
michael-grunder
243cca9cde Merge branch 'multibulk-serialize' into develop
Conflicts:
	redis.c

References #538
2014-12-16 11:22:14 -08:00
michael-grunder
a302564c4c Fix parsing of 'zipped' replies for various uses
As discovered in issue #523, phpredis was attempting to unserialize
both the keys *and* scores for commands like zRangeByScore.  This
had to do with the logic around deserialization in the response.

In addition, this same bug would have caused issues when running
commands like $r->config('get'), because that too, would have tried
to unserialize the values, which we don't want to do.

This commit reworks parsing and zipping up replies by allowing the
call to be configured to unseraialize any combination of keys or
values (or none or both).
2014-10-31 15:00:59 -07:00
michael-grunder
b1ad5435ff ZRANGEBYLEX command
This commit adds the command ZRANGEBYLEX to phpredis, which was
introduced in 2.8.9.  Like with most commands, phpredis will do
some simple validation on the client side, to avoid sending
calls which are not correct (e.g. min/max that aren't valid
for the call, etc).

Addresses #498 and #465
2014-08-30 11:45:09 -07:00
michael-grunder
f78c9f4a15 Merge branch 'hotfix/debug_object' into develop 2014-07-21 12:51:01 -07:00
michael-grunder
96374a9105 Implement DEBUG OBJECT
Addresses #342
2014-07-21 12:50:29 -07:00
michael-grunder
0f1f5f444f Merge branch 'hotfix/win32-fixes' into develop
Conflicts:
	redis.c
2014-07-06 11:04:55 -07:00
michael-grunder
7a80c10905 Remove duplicate pubsub test 2014-07-06 10:58:22 -07:00
Anatol Belski
4d2533706a Merge remote-tracking branch 'vostok4/master'
Conflicts:
	CREDITS
	README.markdown
	config.w32
	library.c
	library.h
	package.xml
	redis.c
	redis_array.c
	redis_array.h
	redis_array_impl.c
	redis_array_impl.h
	tests/TestRedis.php
2014-07-01 16:45:09 +02:00
vostok4
9c12c40a66 Merge nicolasff:b9a16b5ad5 in, fixing for Win32
Now we should be up to master with upstream for an easier merge.
2014-04-09 11:14:45 +02:00
michael-grunder
110a9933a3 Initial commit of HyperLogLog commands
This is the initial commit of the HyperLogLog probabilistic counting
command introduced in Redis.

Support for the following commands is implemented

  * PFADD <key> <member1> <member2> ... <memberN>
  * PFCOUNT <key>
  * PFMERGE <dstkey> <srckey1> <srckey2> ... <srckeyN>
2014-04-01 16:30:11 -07:00
michael-grunder
6c37fa301d Merge branch 'feature/pubsub_cmd' into develop 2014-03-15 10:14:41 -07:00
michael-grunder
e74ffe0366 Implemented BITPOS command
This commit introduces the new BITPOS redis command
http://redis.io/commands/bitpos
2014-03-03 06:23:38 -08:00
michael-grunder
f200730fe9 _serialize method
This commit adds a utility method as a counterpart to the _unserialize
utility method, allowing users to manually serialize data themselves
before sending it to Redis.  This could be useful for calls going through
EVAL, as phpredis can't automatically serialize/unserialize in that case.

Addresses #431
2014-02-04 11:55:08 -08:00
michael-grunder
48ae8e52f6 Implement PUBSUB command
This commit implements the Redis PUBSUB command, a new command
available since Redis 2.8.0 and described here:
http://redis.io/commands/pubsub

Addresses #427
2014-01-21 14:50:34 -08:00
michael-grunder
ab553893f9 SCAN and variants
This commit introduces support for the Redis SCAN, HSCAN, SSCAN,
and ZSCAN commands.

In the case of HSCAN, SSCAN, and ZSCAN, we take a key and iterator
as required arguments, and for SCAN just an iterator.  Matching
the Redis commands, each variant can optionally take a pattern
to match against and a count value which hints at Redis how many
keys to return at a time.

When scanning keys or members (especially with a large keyspace when
searching for a pattern), Redis will sometimes return an empty result
of keys/members.  PHPRedis can be set up to abstract this from the
caller by setting:

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);

Which instructs PHPRedis to keep retrying the scan until members are
returned OR the iteration completes (Redis returns to us a zero iterator).

By default this option is set to Redis::SCAN_NORETRY, meaning that
empty results are possible, requiring an explicit check for FALSE in the
scanning loop, like so:

```php
$it = NULL;
while(($arr_keys = $redis->scan($it, "*pattern*"))!==FALSE) {
	print_r($arr_keys);
}
```
2013-12-14 10:51:03 -08:00
michael-grunder
77afbe3dac Implement WAIT command
This commit implements the new WAIT command which currently lives
in redis unstable, along with a unit test.

Also added myself to the README.markdown file, as well as a link to
"the twitter".
2013-12-07 14:08:18 -08:00
michael-grunder
2108446ecb Don't free the key before we use it
Fixes #408
2013-11-19 07:40:02 -08:00
michael-grunder
32837e06e9 Allow for NULL to be passed in our optional arguments and just
ignore it if it is (but still set the key).

Addresses #407
2013-11-18 11:41:19 -08:00
michael-grunder
eff6a91340 Enforce offset range limitations for GETBIT and SETBIT
Addresses #401
2013-11-13 15:00:13 -08:00
michael-grunder
f3f361a427 Fix serializer support for SRANDMEMBER for both one member
and when the count argument is passed.

Addresses #391
2013-11-13 11:16:41 -08:00
Soenke Ruempler
0f003bcb2d regression test for: setex properly handles long expire values 2013-10-04 10:34:22 -07:00
michael-grunder
b144743345 Rework the HMGET command to skip invalid keys
This relates to a previous hotfix for issue #379 where phpredis
would time out if you sent an array of empty values.  The reason
it was timing out is that the argument count being sent wasn't
reflecting any skipped items in the array (meaning redis was
waiting for the rest of the command).

I realized that the previous fix would still fail if you were to
send some valid values, with invalid (null, empty string, etc)
ones mixed in.

Presently, we're just skipping invalid items in the array but there
might be a case to issue a php_error_docref type warning when we
encounter them, so the user can know that it happened.

In addition, HMGET now uses a smart_str to build the command, which
means the time it takes to build the key will scale in a linear fashion
2013-09-05 15:08:30 -07:00
michael-grunder
a0e9b65d4c Add a unit test for the scenario described in #379 2013-09-03 21:17:38 -07:00
michael-grunder
60e3ba781e Merge branch 'feature/new_set_args' into develop 2013-08-31 14:09:58 -07:00
michael-grunder
bab2a192b7 Fix an erroneous unit test failure for TTL
When using the TTL command, Redis >= 2.8 will return -1 for a key
with no TTL and -2 for a key that doesn't exist.  This fixes the
unit tests so they don't expect this in versions < 2.8.
2013-08-30 21:11:02 -07:00
michael-grunder
7207aae8aa Add SLOWLOG command
Add support for the various slowlog commands you can execute
in Redis, including:

SLOWLOG GET [len]
SLOWLOG RESET
SLOWLOG LIST
2013-08-27 21:26:51 -07:00
Marlies Heijkoop
d01abbbd7d Added tests for zUnion and zInter with aggregate functions but without weights 2013-08-12 21:36:13 +02:00
michael-grunder
711f053b9f Redis >= 2.6.12 extended set options
Implement the new SET options as per the redis documentation:
http://redis.io/commands/set

You can now pass the new options (ex=>sec, px=>milisec, xx, nx) as
an array of options to the SET command and phpredis will handle them.

If you pass key, value, <long> phpredis will still redirect to SETEX
as it did before (to avoid breaking implementations).

Addresses #364
2013-08-02 23:31:27 -07:00
michael-grunder
1b624141c0 Update documentation and unit tests for TTL/PTTL
Addresses #358
2013-07-31 14:57:26 -07:00