3294 Commits

Author SHA1 Message Date
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
d68c30f87d Remove Windows PHP 7.x jobs 2024-05-16 11:44:52 -07:00
michael-grunder
34b5bd81ef Rework how we declare ZSTD min/max constants.
Fixes #2487
2024-05-16 11:44:52 -07:00
divinity76
f865d5b95d fix missing <code> tags 2024-05-13 09:20:10 -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
f350dc342c Test aginst the first stable version of valkey.
Now that valkey has an official release we can test against that and
remove the "continue-on-error" flag in CI.
2024-04-16 11:50:07 -07:00
michael-grunder
3d7be35816 Consolidate failure path 2024-04-09 12:58:45 -07:00
michael-grunder
0e92616591 Fix memory leak if we fail in ps_open_redis. 2024-04-09 12:58:45 -07:00
michael-grunder
9f3ca98c00 Add a test for session compression.
See #2473 #2480
2024-04-08 20:16:27 -07:00
michael-grunder
2b555c89ef Minor session compression cleanup.
* We can compress without the need for sepearate buffers.
* Allow both "" and "none" to mean "none" in terms of
  redis.session.compression.
2024-04-08 15:11:52 -07:00
Michael Grunder
dc39bd55a0 Remove 7.2 and 7.3 from CI. (#2478)
< 8.1 is EOL but no one upgrades when they should so it's probably
prudent to make sure we still compile against 7.4.
2024-04-08 14:53:27 -07:00
bitactive
da4ab0a72c Add compression support for PHP Sessions (#2473)
* Add compression support for PHP Sessions

Previously, compression was available for standard data but not for
session handling. This update enables the compression of PHP sessions,
allowing for more efficient Redis memory usage.

* Move session compress/uncompress logic to helper functions

* Change session_compress_data to always set the out arguments and adjust PS_READ_FUNC
2024-04-08 14:40:15 -07:00
PlavorSeol
5f1eecfba6 Mention Valkey support 2024-04-08 11:46:52 -07:00
michael-grunder
59965971bb Add a CI step that waits for server instances before running tests
Every so often our tests will fail because we attempt to interact with
one of the daemonized server instances before it has enough time to
actually start.

Usually this happens when we try to use the cli tool to execute
`--cluster-create`, but it can occur elsewhere as well.

This commit adds a step that waits for every instance that we started to
actually be up before trying to create the cluster and run subsequent
unit tests.

Additionally it switches from `$(seq a b)` to the `{a..b}` brace
expansion.
2024-04-08 10:38:13 -07:00
michael-grunder
a819a44b83 Test against valkey
Add Valkey to our server matrix in addition to making the jobs a bit
more efficient by only installing the specific server we're testing on
each run.

For now we allow tests to fail against Valkey as they don't yet have an
official release.  Once there is an official release we'll remove the
`continue-on-error` setting for Valkey.
2024-04-07 13:35:07 -07:00
Bitactive
b698901818 Support for early_refresh in Redis sessions to match cluster behavior
Previously, the redis.session.early_refresh feature was implemented for
Redis Cluster, utilizing GETEX for the initial session read to minimize
the number of commands sent to the Redis server. However, this enhancement
was not applied to non-cluster sessions. This update addresses this
discrepancy, ensuring consistent behavior between Redis and Redis Cluster.
2024-03-28 13:19:47 -07:00
Jozsef Koszo
eb7f31e7af Fix random connection timeouts with Redis Cluster
When a node timeout occurs, then phpredis will try to connect to another
node, whose answer probably will be MOVED redirect. After this we need
more time to accomplish the redirection, otherwise we get "Timed out
attempting to find data in the correct node" error message.

Fixes #795 #888 #1142 #1385 #1633 #1707 #1811 #2407
2024-03-25 12:04:06 -07:00
Pavlo Yatsukhnenko
8323ddff80 Merge pull request #2471 from phpredis/dump-arginfo-zpp-mismatch
Fix Arginfo / zpp mismatch for DUMP command
2024-03-25 20:17:28 +02:00
Pavlo Yatsukhnenko
50e5405c03 Fix Arginfo / zpp mismatch for DUMP command 2024-03-25 19:28:29 +02:00
Tim Starling
37fa3592ce Mention KeyDB support in README.md
Mention support for KeyDB in README.md.

Remove credit for Owlient from the first paragraph. Owlient was acquired by Ubisoft in 2011, so presumably no longer benefit from such prominent credit.
2024-03-25 09:23:33 -07:00
michael-grunder
54d62c7240 Add KeyDB to CI
See: #2466
2024-03-22 19:08:45 -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
David Baker
c7a73abbd5 Remove mention of pickle 2024-03-21 20:05:02 -07:00
Pavlo Yatsukhnenko
f358687c72 Merge pull request #2467 from phpredis/multi-exec-segfault
Fix segfault and remove redundant macros
2024-03-21 17:59:07 +02:00
Pavlo Yatsukhnenko
a9e53fd16e Fix segfault and remove redundant macros
Replace `SOCKET_WRITE_COMMAND` with `redis_sock_write` because it can't be used
with pre-defined commands (it frees memory in case of failed writing operation).
After replacement `SOCKET_WRITE_COMMAND` becomes redundant so remove it.
2024-03-21 15:14:36 +02:00
Martin Vancl
8a39caebe8 add: session.save_path examples 2024-03-18 15:20:13 -07:00
michael-grunder
3dbc2bd814 Don't use deprecated string interpolation syntax. 2024-03-18 15:14:18 -07:00
michael-grunder
a51215ce2b Update random includes.
PHP 8.4 has some breaking changes with respect to where PHP's random methods and
helpers are.  This commit fixes those issues while staying backward compatible.

Fixes #2463
2024-03-18 15:14:07 -07:00
michael-grunder
2612d444e5 Update RedisCluster scan logic for large SCAN cursors.
We also need to update the `RedisCluster` logic to handle very large
curosr values, in addition to handling them for the `Redis` and
`RedisArray` classes.

See #2454, #2458
2024-03-18 11:54:02 -07:00
michael-grunder
e52f0afaed Update SCAN to handle very large cursor values.
Technically Redis may return any unsigned 64 bit integer as a scan
cursor.  This presents a problem for PHP in that PHP's integers are
signed.  Because of that if a scan cursor is > 2^63 it will overflow and
fail to work properly.

This commit updates our SCAN family of commands to deliver cursors in
their string form.

```php
public function scan(null|int|string $iterator, ...);
```

On initial entry into our SCAN family we convert either a NULL or empty
string cursor to zero, and send the initial scan command.

As Redis replies with cursors we either represent them as a long (if
they are <= ZEND_ULONG_MAX) and as a string if greater.  This should
mean the fix is minimally breaking as the following code will still
work:

```php
$it = NULL;
do {
    print_r($redis->scan($it));
} while ($it !== 0);
```

The `$it !== 0` still works because the zero cursor will be represented
as an integer.  Only absurdly large (> 2^63) values are represented as a
string.

Fixes #2454
2024-03-17 10:59:14 -07:00
michael-grunder
fa1a283ac9 Fix some typos 2024-03-13 13:46:58 -07:00
michael-grunder
4d233977a5 Update stubs 2024-03-13 13:07:26 -07:00
Michael Grunder
ece3f7bebc Fix config.m4 when using custom dep paths (#2453)
* We need both PHP_ADD_LIBRARY_WITH_PATH and PHP_ADD_INCLUDE

Fixes #2452

* Add an initial test block for ./configure correctness.
2024-03-04 21:03:01 -08:00
Benjamin Morel
77ab62bccb Tighter return types for Redis::(keys|hKeys|hVals|hGetAll)() 2024-02-21 13:17:23 -08:00
michael-grunder
732e466a6a Improve warning when we encounter an invalid EXPIRY in SET
We actually had two different bits of logic to handle EXPIRY values in
the `SET` command.  One for the legacy `SET` -> `SETEX` mapping and
another for the newer `SET foo bar EX <expiry>`.

Additionally the error message could be confusing.  Passing 3.1415 for
an `EX` expiry would fail as we didn't allow floats.

This commit consolidates expiry parsing to our existing helper function
as well as improves the `php_error_docref` warning in the event that the
user passes invalid data.  The warning will now tell the user the type
they tried to pass as an EXPIRY to make it easier to track down what's
going wrong.

Fixes #2448
2024-02-21 13:16:36 -08: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
SplotyCode
142c1f4a93 Fix retry_internal documentation 2024-02-13 14:07:34 -08:00
Takayasu Oyama
8f8ff72a79 Update zCount argument type in redis.stub.php (#2439)
* Update zCount argument type in redis.stub.php

zCount's min/max can also be an integer.

* fix arginfo
2024-01-24 12:46:50 -08:00
Pavlo Yatsukhnenko
5d293245cd Fix Redis::mget signature 2024-01-16 13:43:51 -08:00
michael-grunder
a4a283ab50 Change exec return method type hint 2024-01-16 13:43:16 -08:00
Alexandre Choura
14f93339c0 fix: RedisCluster::publish returns a cluster_long_resp 2024-01-16 12:58:17 -08:00
woodong
3fdd52b42d Fix the time unit of retry_interval 2024-01-16 11:23:00 -08:00
michael-grunder
6dc0a0be8d Fix segfault when passing just false to auth.
Fixes #2430
2024-01-09 12:55:06 -08:00
Pavlo Yatsukhnenko
f4ede5a637 Merge pull request #2429 from phpredis/session-tests
Set sessionSaveHandler
2023-12-20 08:36:42 +02:00
Pavlo Yatsukhnenko
9f8f80ca9d sessionSaveHandler 2023-12-19 20:01:47 +02:00