Commit Graph

577 Commits

Author SHA1 Message Date
Remi Collet
cc1be32294 fix 2 tests with redis 6.2 2024-09-24 14:47:04 +02:00
Remi Collet
bff3a22e9d fix implicit nullable (8.4) 2024-09-23 11:08:56 -07:00
Viktor Djupsjöbacka
6ea5b3e08b Fix argument count issue in HSET with associative array, update method signature for HSET and add documentation 2024-07-17 12:47:49 -07:00
michael-grunder
6673b5b2be SRANDMEMBER can return any type because of serialization. 2024-07-13 23:12:25 -07:00
Michael Grunder
99f9fd8353 Fix HRANDFIELD command when WITHVALUES is used. (#2524)
Redis requires the user to send a count if `WITHVALUES` is specified,
otherwise it sees the `WITHVALUES` argument as the count and will error
out that it's not a number.

We can also return false if the key doesn't exist.
2024-07-13 22:42:25 -07:00
Michael Dwyer
eeb5109967 Update documentation (#2523)
* Remove/update mentions of removed methods

These methods were deprecated in a previous release

* Correct documentation for zInter/zinterstore

* Correct documentation for zUnion/zunionstore

* Add documentation for zDiff/zdiffstore

* Add documentation for zMscore
2024-07-11 21:49:29 -07:00
michael-grunder
981c69314d Add GETEX to README docs + minor change to command.
* Adds `GETEX` to the README.md documentation.
* Allow the user to send `PERSIST` either as an array key or just in the
  array, to conform with similar methods.
* Implement getEx for `RedisCluster`

Fixes #2512
2024-06-20 13:56:17 -07:00
Michael Grunder
57304970cd PHP might throw a fatal error if we send no args to exists (#2510) 2024-06-18 16:05:21 -07:00
Michael Grunder
b1771defdc More unit test utility functions/usage. (#2509)
* More unit  test utility functions/usage.

* Add `assertKeyEquals` and `assertKeyEqualsWeak` as we test key values
  hundreds of places in `RedisTest.php`

* We are almost always using `$this->redis` when we want to run an
  assertion that needs access to the client, so make this argument
  optional and default to `$this->redis`.

* Update a few more assertions to use our new methods.

* Various minor fixes/tweaks.

* Update RedisTest.php

typo
2024-06-18 14:53:22 -07: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
d3b2d87b10 Don't use $k1 as a variable name.
There is a very strange edge case whn you try to run PHP under valgrind
and use certain specific strings like "$k1".

PHP interns these values in such a way that valgrind can't handle it and
hard aborts on sigsegv.  I don't know what the actual cause is but
simply renaming the variables is a workaround.
2024-06-01 17:35:58 -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
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
michael-grunder
3dbc2bd814 Don't use deprecated string interpolation syntax. 2024-03-18 15:14:18 -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
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
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
Pavlo Yatsukhnenko
2b2bc042da Merge pull request #2327 from phpredis/sentinel
Synchronize Redis and RedisSentinel constructors
2023-03-01 22:08:12 +02: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
ebb2386e52 Synchronize Redis and RedisSentinel constructors 2023-02-12 22:33:45 +02: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
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