278 Commits

Author SHA1 Message Date
michael-grunder
0d89e92889 Spelling fixes 2024-05-28 21:05:08 -07:00
michael-grunder
e18f6c6d9e Minor refactor 2024-05-28 20:32:50 -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
0f94d9c1c6 Relax timing test slightly 2024-05-09 21:30:17 -07:00
michael-grunder
c0d6f04298 Minor improvements to some session tests. 2024-05-09 20:45:07 -07:00
michael-grunder
9f3ca98c00 Add a test for session compression.
See #2473 #2480
2024-04-08 20:16:27 -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
9b90c03bd0 Update WAITAOF test to use different assertion + add debug info
* Add what value failed to pass our callback assertion so we can see
  what we actually got from the server.

* WAITAOF requires Redis >= 7.2.0 so don't run it if the server is older
  than that.
2024-02-20 12:00:54 -08:00
michael-grunder
ed7c9f6f63 Implement WAITAOF command. 2024-02-14 12:03:29 -08:00
Pavlo Yatsukhnenko
9f8f80ca9d sessionSaveHandler 2023-12-19 20:01:47 +02:00
michael-grunder
a7f51f70cc Fix flaky test and OBJECT in a pipeline.
* We weren't properly passing `z_tab` through to the underlying OBJECT
  handler, which was causing PhpRedis to crash if you tried to execute
  the OBJECT command in a pipeline.

* Rework the `testTouch` unit test to try and avoid erroneous failures
  due to CI instance CPU scheduling.
2023-10-10 18:39:08 -07:00
michael-grunder
7825efbced Ensure we're talking to redis-server in our high ports test.
Instead of just checking whether or not something is listening on the
high ports, send a quick PING to make sure.

We're not just using another Redis instance because the point of the
test is to protect against a regression when connecting to high port
numbers.
2023-09-20 09:36:41 -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
Remi Collet
dcb95a3f06 change expected value according to redis version 2023-03-23 14:43:31 -07:00
Remi Collet
fea19b5229 fix testObject for redis 7.2 2023-03-23 14:43:31 -07:00
michael-grunder
ccd419a4c8 Small refactor of some methods
* Use our `redis_cmd_append_sstr_key_*` and `redis_cmd_append_sstr_zval`
  wrappers, which handle key prefixing and serialization transparently.

* Rework ZADD so it can handle the bulk double response from the `INCR`
  options.
2023-03-01 11:45:47 -08:00
michael-grunder
02c91d59cb Fix RPOP to unserialize/decompress data.
Fixes #2329
2023-02-24 12:01:43 -08:00
Pavlo Yatsukhnenko
7c46ad2c05 Issue #2068
Add FCALL/FCALL_RO commands
2022-12-24 13:37:50 +02: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
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
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
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
ff863f3f97 Refactor command command
Issue #2068
2022-11-19 14:04:38 +02:00
michael-grunder
0b7bd83f57 Add more docblocks and fix XAUTOCLAIM response handler.
- Finish adding docblocks with examples for all of the stream commands.
- Fix XAUTOCLAIM response handler (the reply has a slightly different
  structure to XCLAIM.
2022-11-15 23:29:45 -08:00
michael-grunder
450904f75c Documentation: More docblocks with examples. 2022-11-07 18:17:48 -08:00
Pavlo Yatsukhnenko
2a0d1c1e6d Refactor PubSub command 2022-10-31 17:01:35 -07:00
Pavlo Yatsukhnenko
e8f5b51748 Move options to the end list 2022-10-30 12:00:12 -07:00
Pavlo Yatsukhnenko
2bb6403883 Issue #1894
Add the CH, NX, XX arguments to GEOADD
2022-10-30 12:00:12 -07:00
michael-grunder
af13f951aa Fix BITOP cross-slot bug
Fixes #2210
2022-10-27 07:45:08 -07:00
michael-grunder
43da8dd9d8 Refactor BRPOPLPUSH and add B[LR]POP documentation 2022-10-26 18:55:55 -07:00
michael-grunder
dc1f2398d0 TOUCH command
Implement the TOUCH command and refactor several of our "variadic key"
commands, which were previously all using their own specific handlers.

While refactoring the code, I changed `EXISTS` to require one key (it
had previously been set to require zero keys).

Additonally, it looks like we had a disparity in two commands which
should be idential to PhpRedis:  SINTERSTORE and SUNIONSTORE.
Previously, SINTERSTORE required only one argument but SUNIONSTORE 2.

I simply changed SUNIONSTORE to also only require a single argument,
since that argument could be an array.

```php
$redis->sInterStore(['dst', 'src1', 'src2']);
$redis->sUnionStore(['dst', 'src1', 'src2']);
```
2022-10-26 01:38:42 -07:00
michael-grunder
69355faae0 Future proof our igbinary header check
See: #2194
2022-10-24 00:25:20 -07: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
8c7c5a3aa2 Refactor SORT and add SORT_RO command
See #2068
2022-10-23 13:18:13 -07:00
michael-grunder
1343f50083 XGROUP DELCONSUMER and ENTRIESREAD
Refactor XGROUP and implement the new DELCONSUMER (Redis 6.2.0) and
ENTRIESREAD (Redis 7.0.0) options.  Additionally, add a proper phpdoc
block to the stub file.

See #2068
2022-10-23 11:37:20 -07:00
michael-grunder
71bcbcb973 Implement ZRANGESTORE and add ZRANGE options
* Add ZRANGESTORE command.

* Add Redis 6.2's `REV`, `BYLEX`, and `BYSCORE` to ZRANGE options.

* Refactor several ZRANGE family commands into a single reply and
  options handler, using PHP's new argument parsing macros.

* Extend our tests to use the new ZRANGE options.

See #1894
2022-10-22 12:46:01 -07:00
michael-grunder
f3a408305a EVAL_RO and EVALSHA_RO
Implement Redis 7.0.0's readonly eval variants

See: #2068
2022-10-21 23:35:09 -07:00
michael-grunder
5dcf3f802b Newer versions of Redis shouldn't need a long delay 2022-10-20 15:04:45 -07:00
michael-grunder
d87f142826 Refactor SLOWLOG command
Refactor the slowlog command to use the new argument parsing API and
also change it so we no longer manually handle atomic/non-atomic
logic in the handler itself.
2022-10-19 12:58:39 -07:00
michael-grunder
36ef4bd8d1 Variadic CONFIG GET/SET
Redis 7.0.0 allows for getting and setting multiple config values as an
atomic operation.  In order to support this while maintaining backward
compatibility, the CONFIG command is reworked to also accept an array of
values or keys and values.

See: #2068
2022-10-19 09:15:16 -07:00
michael-grunder
44d03ca00a INFO with multiple sections
See #2068
2022-10-16 11:31:43 -07:00
michael-grunder
4d8afd387e Refactor BITPOS and implement BIT/BYTE option.
Update BITPOS to use the new argument parsing macros as well as
implement Redis 7.0.0's BIT/BYTE modifier.

Additionally I changed `int $bit` to `bool $bit` as its a more
appropriate datatype.

See #2068
2022-10-13 11:53:57 -07:00
michael-grunder
872ae1079f Implement Redis 7.0.0 [P]EXPIRE[AT] options
See #2068
2022-10-13 11:31:28 -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