88 Commits

Author SHA1 Message Date
michael-grunder
0ed0fc0562 Add Redis::REDIS_VECTORSET type.
Redis >= 8.0 has a new type `vectorset` that we should support like all
the other types.
2025-08-28 09:34:07 -07:00
michael-grunder
8d369f4d62 Implement GEOSEARCH[STORE] BYPOLYGON.
Valkey 9.0.0 implemented a new variant of `GEOSEARCH` where you supply
the verticies to an arbitrary polygon.

Since we can't modify the `geosearch` prototype using it is a little
wonky (you need to just pass empty strings for position and unit).

```php
$redis->geosearch('ca:cities', '', [
    -121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], '');
$redis->geosearchstore('ca:cities', 'dst', '', [
    -121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], '');
```
2025-08-24 06:37:51 -07:00
michael-grunder
8014000369 Attempt to fix flaky GitHub CI tests.
We often have to rerun the test suite on GitHub actions because of a
hard to reproduce "Read error on connection" exception when getting a
new `RedisCluster` instance.

No one has ever reported this failure outside of GitHub CI and it's not
clear exactly what might be going on.

This commit does two main things:

1. Allows for one failure to construct a new `RedisCluster` instance but
   only if we detect we're running in GitHub CI.

2. Adds much more diagnostic information if we still have a fatal error
   (e.g. we can't connect in two tries, or some other fatal error
   happens). The new info includes the whole callstack before aborting
   as well as an attempt to manually ping the seeds with `redis-cli`.
2025-05-08 09:19:12 -07:00
Michael Grunder
60ca48f3ce Redis Cluster does not have SELECT. (#2644) 2025-04-01 11:33:44 -07:00
Michael Grunder
0445e683e7 Refactor getWithMeta logic (#2643)
* Refactor `getWithMeta`

* Consolidate `getWithMeta()` test.

* Review comments
2025-03-31 12:42:29 -07:00
michael-grunder
fa3eb00683 Add tests for serverName() and serverVersion() 2025-03-20 14:18:44 -07:00
Pavlo Yatsukhnenko
807f806fe8 Reorganize tests 2025-02-25 17:40:23 +02:00
Pavlo Yatsukhnenko
9036ffca6a Add getWithMeta method 2025-02-25 16:27:10 +02:00
michael-grunder
a2eef77f44 Implement Valkey >= 8.1 IFEQ set option
Implement the new `IFEQ` `SET` option that will be included in `Valkey`
8.1.

See: valkey-io/valkey#1324
2025-01-20 08:04:27 -08:00
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
dab6a62d34 Code formatting 2024-05-31 12:15:54 -07:00
michael-grunder
c6cd665bde Code formatting 2024-05-30 12:10:46 -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
3c125b09f4 More unit test cleanup.
* Tighten up `assertTrue` and `assertFalse` such that they test that
  passed arguments `===` `true` and `===` `false` respectively, instead
  of testing for truth-like or false-like.

* Start modernizing our unit tests to use explicit types for arguments,
  return types, member variables, etc.

* Multiple assertion fixes that were exposed when making `assertTrue`
  and `assertFalse` more explicit.

* Some formatting cleanup to style for incorrect indentation, etc, that
  had crept in over many years.

* Add some more assertion helpers like `assertNull`, `assertGT`,
  `assertGTE`, `assertLT`, and `assertLTE`.
2024-05-28 20:13:12 -07:00
michael-grunder
18b0da727b Update unit test assertions.
Our tests have a ton of instances where we do something like:

```php
$this->assert(TRUE === $this->redis->command1());
$this->assert($this->redis->command2() === 42);
```

Which should be written like this:

```php
$this->assertTrue($this->command1());
$this->assertEquals(42, $this->command2());
```

Additionally it changes some assertions to use more relevant assertions
like `assertInArray` rather than `assertTrue(in_array())`.

* Add `assertEqualsCanonicalizing` assertion similar to what PHPUnit
  has.

* Add `assertStringContains` helper assertion.
2024-05-27 20:49:46 -07:00
Michael Grunder
b88e72b1e6 Refactor session tests (#2492)
* Refactor session tests

* Update these external scripts to take formal arguments with `getopt` to
  make it more straightforward what each of the currently positional
  arguments are actually for.

* Create small helper classes for invoking these external scripts.
  Instead of `startSessionProcess` that takes a dozen argument all but
  three of which have defaults, we can use a construct like this:

  ```php
  $runner = $this->sessionRunner()
      ->maxExecutionTime(300)
      ->lockingEnabled(true)
      ->lockWaitTime(-1)
      ->lockExpires(0)
      ->data($data)
      ->compression($name);

  // Invokes startSession.php with above args.
  $result = $runner->execFg();

  // Invokes regenerateSessionId.php with above args
  $new_id = $runner->regenerateId();

  // Invokes getSessionData.php for this session ID.
  $data = $runner->getData();
  ```

* Add a bit of logic to TestSuite to dump more information about the
  source of an assertion to make it easier to track down problems when
  we assert outside of a top level public `test_*` method.

* Create a few new assertions like `assertKeyExists` and
  `assertKeyMissing` which will generate much nicer assertions as
  opposed to

```php
$this->assertTrue($this->redis->exists($some_key));
```

* If our externally spawned session scripts fail output the exact call
  that was made along with all arguments as well as the output that we
  received to make it easier to narrow down.

* snake_case -> camelCase
2024-05-23 09:43:36 -07:00
michael-grunder
d9c48b788d KeyDB: Get our tests passing against KeyDB.
This commit fixes our unit tests so they also pass against the KeyDB
server.  We didn't ned to change all that much.  Most of it was just
adding a version/keydb check.

The only change to PhpRedis itself was to relax the reply requirements
for XAUTOCLAIM.  Redis 7.0.0 added a third "these elements were recently
removed" reply which KeyDB does not have.

Fixes #2466
2024-03-22 07:47:43 -07:00
Viktor Szépe
37c5f8d451 Fix typos 2024-02-21 13:16:12 -08:00
michael-grunder
ed7c9f6f63 Implement WAITAOF command. 2024-02-14 12:03:29 -08:00
Pavlo Yatsukhnenko
954fbab896 Use newInstance in RedisClusterTest 2023-10-02 15:16:34 +03:00
Pavlo Yatsukhnenko
0672703ba8 Fix cluster nodes from ENV 2023-09-22 14:57:48 +03:00
Pavlo Yatsukhnenko
eda399583d Cluster nodes from ENV 2023-09-22 12:23:43 +03: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
Pavlo Yatsukhnenko
90a0e9cc0e Add Redis::function command 2022-12-18 18:21:42 +02:00
michael-grunder
27900f39d2 Implement new ZSET commands for cluster
* Implement `ZDIFF`, `ZINTER`, `ZUNION`, `ZMSCORE`, and
  `ZRANDMEMBER` for `RedisCluster`.
* Refactor `ZUNIONSTORE` command and switch to using our centralized
  zset option parsing handler.

See #1894
2022-12-02 09:11:00 -08:00
michael-grunder
40a2c254e2 Implement COPY for RedisCluster
* Refactor `redis_copy_cmd` to use the new argument parsing macros.
* Add a handler in `RedisCluster`.

See #1894
2022-12-01 22:38:19 -08:00
michael-grunder
e222b85ecf Implement HRANDFIELD for RedisCluster
See #1894
2022-12-01 22:12:19 -08:00
Michael Grunder
fa5d1af9ff Implement GEOSEARCH and GEOSEARCHSTORE for RedisCluster. (#2277)
* Implement GEOSEARCH and GEOSEARCHSTORE for RedisCluster.

See #1894
2022-12-01 21:54:15 -08:00
michael-grunder
7121aaae5c Implement LPOS for RedisCluster
See #1894
2022-12-01 14:05:43 -08:00
michael-grunder
121e9d9c29 Implement BLMOVE and add LMOVE/BLMOVE to cluster.
* Refactor `redis_lmove_cmd` to work for both `LMOVE` and `BLMOVE`
* Implement `LMOVE` and `BLMOVE` in RedisCluster.

See #1894
2022-12-01 13:48:03 -08:00
michael-grunder
abfac47be0 Implement SMISMEMBER for RedisCluster
See #1894
2022-11-30 17:55:30 -08:00
michael-grunder
90828019de Refactor network IO tracking.
* Create inline wrappers of the low-level php_stream_* functions that
  also keep track of the number of bytes written/read.

* Change the logic to aggregate network traffic until the user
  explicitly "resets" it.  I think this will be a more common use-case
  (running many commands and then seeing overall network IO).

See #2106
2022-11-25 13:41:47 -08:00
Pavlo Yatsukhnenko
e0a88b7bdf Issue #2106
Expose the transferred number of bytes
2022-10-24 09:18:19 +03:00
Pavlo Yatsukhnenko
d73f3f4b08 Issue #2106 2022-10-24 09:17:22 +03:00
Michael Grunder
e392dd88dd RedisCluster stub fixes (#2183)
RedisCluster stub fixes

I can now run RedisCluster unit tests within a PHP build tree build in
debug mode without any deprecation warnings or arginfo/zpp errors.
2022-10-12 13:16:43 -07:00
michael-grunder
74cf49f554 More redis.stub.php and PHP 8.2 deprecation fixes.
With this commit, I can now run the full `--class Redis` unit test suite
inside of a PHP8.2.x buiild tree and have them pass and not throw any
fatal zpp argument errors.
2022-10-11 12:51:30 -07:00
michael-grunder
54a084e51c Refactor FLUSHDB and update docs.
Fixes #2096
2022-10-10 23:04:17 -07:00
michael-grunder
239678a03b Implement CONFIG RESETSTAT
Rework the CONFIG command and add RESETSTAT variant.

Fixes #1673
2022-10-01 10:24:53 -07:00
michael-grunder
98fda1b870 Make sure we set an error for key based scans
See #1661
2022-09-28 23:18:53 -07:00
Pavlo Yatsukhnenko
687a5c7880 Issue #1943
Add lPos command.
2022-08-03 22:28:08 +03:00
Pavlo Yatsukhnenko
fe397371ef Issue #1894
Add Redis::hRandField command
2022-04-12 22:00:04 +03:00
Pavlo Yatsukhnenko
947a2d3897 Issue #1894 2022-04-11 21:57:12 +03:00
Pavlo Yatsukhnenko
b344649b6f [WIP] Issue #1894
Add geosearch and geosearchstore commands.
2021-12-28 21:17:19 +02:00
Pavlo Yatsukhnenko
ee550fb990 Issue #2009 2021-12-13 20:14:26 +02:00
Pavlo Yatsukhnenko
d5cf52cb8a [WIP] Issue #1894
Add Redis::zinter and Redis::zunion commands
2021-03-20 23:29:08 +02:00
michael-grunder
1a0ae97ef5 Fix PhpRedis session tests to soften timing issues
Rework the session locking unit tests to be less reliant on arbitrary
sleep calls which can be very troublesome when running in Travis and
especially when running in Travis under valgrind.

Additionally, skip multiple newly added Redis 6.2 commands that aren't
yet implemented in RedisCluster.
2021-03-10 18:59:54 -08:00
Michael Grunder
950e8de807 Issue.1847 cluster segfault (#1850)
Fix for #1847 when dealing with NULL multi bulk replies in RedisCluster.

Adds `Redis::OPT_NULL_MULTIBULK_AS_NULL` setting to have PhpRedis
treat NULL multi bulk replies as `NULL` instead of `[]`.

Co-authored-by: Alex Offshore <offshore@aopdg.ru>
2020-09-28 11:07:46 -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
Pavlo Yatsukhnenko
890ee0e656 TravisCI: test tls connect 2020-06-05 09:40:53 +03:00
Pavlo Yatsukhnenko
e80600e244 Issue #548 (#1649)
Adds `Redis::SCAN_PREFIX` and `Redis::SCAN_NOPREFIX` as options to SCAN.

See #548
2020-05-18 18:11:40 -07:00