Commit Graph

3393 Commits

Author SHA1 Message Date
Ilia Alshanetsky b112875b70 session: derive lock secret from php_random_bytes_silent
generate_lock_secret derived the secret from hostname plus pid,
roughly 22 bits of guessable entropy and also readable from Redis
under <key>_LOCK. Replace with 16 bytes from php_random_bytes_silent,
hex-encoded.

Defense in depth: an attacker with write access to the Redis
instance can already bypass the lock by DELing the key, so this is
not a primary defense; worth fixing for the case where only the
lock key itself is exposed. The hostname|pid path stays as a fallback
when php_random_bytes_silent fails, so the caller always gets a
non-NULL secret.
2026-05-19 17:23:08 -07:00
Arshid b83af6417b Fix serialization failure handling for anonymous classes (#2838)
* Fix serialization failure handling for anonymous classes
2026-05-11 19:54:02 -07:00
Arshid b8b29687c1 Update redis_commands.c
Co-authored-by: Michael Grunder <michael.grunder@gmail.com>
2026-05-01 09:11:14 -07:00
arshidkv12 fe67b8cb33 fix: fix: correct snprintf format specifier for long value 2026-05-01 09:11:14 -07:00
michael-grunder f5ed17048b Update doctum docs 2026-04-08 18:42:21 -07:00
武田 憲太郎 82bf96c3c0 Fix flaky testExists by using deterministic key setup
The test used rand() to decide which keys to create, making it
possible for $mkeys to be empty. This caused EXISTS to receive an
empty array, resulting in a sporadic assertion failure:
(false) !== 0

Observed in #2825 CI and also in an unrelated branch:
- https://github.com/phpredis/phpredis/actions/runs/24132080914
- https://github.com/phpredis/phpredis/actions/runs/23617186872
2026-04-08 13:05:32 -07:00
michael-grunder 5b19731649 Update GCRA optional argument from NUM_REQUESTS to TOKENS.
See: https://github.com/redis/redis/pull/14950
2026-04-08 09:33:00 -07:00
michael-grunder 9a17083125 Tiny refactor of 8.6 save path compatibility
When `save_path` is a `zend_string` we don't have to calculate the
length.
2026-03-26 14:29:13 -07:00
michael-grunder 60eb01c4dc CI: Add a timeout when waiting for Redis instances
Rarely CI hangs forever (or until it hits the maximum workflow execution
time) when Redis doesn't come up properly.

This just adds a configurable timeout so we can rerun the workflow when
it hangs.
2026-03-26 14:28:53 -07:00
Rasmus Lerdorf b8b765e610 Fix compilation against PHP 8.6 (session save_path is now zend_string*) 2026-03-26 09:58:02 -07:00
michael-grunder df243455e6 Docs: Update generated API documentation 2026-03-25 11:03:42 -07:00
michael-grunder 10b77a42d6 Implement GCRA command 2026-03-25 11:03:42 -07:00
林博仁 Buo-ren Lin c99c86349a docs: document the default value of the persistent parameter for PHP session handler
Signed-off-by: 林博仁(Buo-ren Lin) <buo.ren.lin@gmail.com>
2026-03-25 11:03:10 -07:00
Sowmya Mallur 0340599b90 docs: document read_timeout parameter for PHP session handler
Made-with: Cursor
2026-03-17 12:55:40 -07:00
Victor Kislov 52e90650b1 cluster_library.c - cluster_send_command - Clear slots cache, if nodes are unreachable 2026-03-10 08:53:31 -07:00
michael-grunder d90cfdb6bd Fix memory leak 2026-03-04 18:31:02 -08:00
michael-grunder e39d9b74f4 Modernize session locking
Add support for Redis' `DELEX` and Valkey's `DELIFEQ` when deleting the
session lock key. Local testing shows about a 10-15% improvement over
the current `EVAL[SHA]` strategy.

This commit adds a new INI settingg:
```ini
redis.session.lock_release_cmd = delex|delifeq|eval
```

By default we continue to use the `EVAL` logic and if a user specifies
another mechanism but the command doesn't exist, we warn the user and
fall back to EVAL.

This commit also refactors a few functions to avoid UB and simplify key
construction.
2026-03-01 14:52:39 -08:00
derrickschoen 409508afa2 fix: Accept null for $seeds in RedisCluster::__construct
The stub declares $seeds as ?array but the C code used format
specifier 'a' (non-nullable) instead of 'a!' in
zend_parse_method_parameters. This caused new RedisCluster(null, null)
to throw TypeError instead of RedisClusterException, contradicting
the declared type signature.

Also treat z_seeds == NULL the same as ZEND_NUM_ARGS() < 2 so that
explicitly passing null falls through to INI-based seed loading,
matching the behaviour when the argument is omitted entirely.

Fixes GH-2810.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 14:35:36 -08:00
michael-grunder 741abf09ec s/relay_/redis_/g 2026-02-19 13:39:18 -08:00
Michael Telgmann 481f12f84c fix: Regenerate arginfo files 2026-02-18 09:50:53 -08:00
Michael Telgmann 26a73f46d1 fix: Add missing method annotation in RedisArray 2026-02-18 09:50:53 -08:00
Michael Telgmann 6aea98f632 fix: Add variadic parameter syntax to PHPDocs 2026-02-18 09:50:53 -08:00
michael-grunder b97951cddc Rework TLS context logic
Instead of currying around a `php_stream_context` object, just retain
the context array provided by the user itself like we do with other
connection information like host and port. This lets users reconnect in
a loop without leaking memory.

```php
$redis = new \Redis;
while (true) {
    // Previously each reconnect call would leak the
    // `php_stream_context` structure.
    $redis->connect('tls://127.0.0.1', 9999, 1, null, 0, 0, [
        'stream' => ['verify_peer' => false, 'verify_peer_name' => false],
    ]);

    $redis->ping();

    $redis->close();
}
```
2026-02-18 09:46:55 -08:00
Pavlo Yatsukhnenko 3568497c45 Merge pull request #2806 from phpredis/fix/stubs
Fix typo
2026-02-16 19:01:14 +02:00
Pavlo Yatsukhnenko 9f4302c0cc Fix typo 2026-02-16 10:46:25 +02:00
michael-grunder 93cb921158 Minor DELEX refactor
We had a `delExType` enum which was later made redundant by
`redisEqType` as they have the same semantics.

This commit just removes `delExType` and uses the new enum.
2026-02-02 00:17:43 -08:00
michael-grunder 6f42a3493d Add a regression test for numeric strinig fields and key names
See #2795, #2796
2026-01-13 17:46:31 -08:00
Pavlo Yatsukhnenko 7c1c125974 Fix issue with numeric strings as hash fields 2026-01-12 11:08:45 -08:00
michael-grunder cab0505155 Fix deserializing non-string keys
In `array_zip_values_and_scores` we were blindly calling `Z_STR_P` on
the `zval` assuming it must be a string.

This isn't the case however if the user did something like this:

```php
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$redis->zAdd('zs', 3.14, ['pi', 'is', 'cool']);

// segfault when we try to get `Z_STR_P` from `['pi', 'is', 'cool']`
$redis->zRange('zs', 0, -1, true);
```

Potential fix for #2791
2026-01-09 09:04:38 -08:00
Pavlo Yatsukhnenko 8f8272dbf1 Migrate to php/php-windows-builder for Windows builds 2026-01-09 08:35:44 -08:00
Emre Çalışkan a6313d1bda fixed "tee: /opt/homebrew/etc/php/8.5/conf.d/90-redis.ini: No such file or directory" 2025-12-01 09:01:00 -08:00
Emre Çalışkan ac54591d1e Added 8.5 to Mac and Windows CI 2025-12-01 09:01:00 -08:00
michael-grunder 0debad4c83 Relax the _digest() test for PHP < 8.1
Just make sure the method is sound. We don't really care about specific
exception messages.
2025-11-27 12:23:46 -08:00
michael-grunder d4600a2846 docs: Update rendered docs 2025-11-26 18:22:57 -08:00
michael-grunder 399346e51a docs: Add a few missinig examples 2025-11-26 18:22:57 -08:00
michael-grunder 4baad44bcf Handle false from $this->redis->info() in TestSuite::setUp()
Technically `INFO` can return false in the event of a protocol error or
similar. If that happens the tests are unlikely to be useful but we
should at least account for it to avoid an immediate fatal error when
calling helpers like `detectKeyDB` and `detectValkey`.

See #2783
2025-11-25 14:43:28 -08:00
michael-grunder f23da62a9b Add missing type results and remove ancient TODO line 2025-11-18 22:41:39 -08:00
michael-grunder a033e40b7b Fix MSETEX TTL assertions
We want to include the actual TTL itself in our range.
2025-11-18 11:19:52 -08:00
michael-grunder 6efd549a1a Clarify that Redis->connect() will throw on failure.
Fixes #2778
2025-11-18 10:56:26 -08:00
michael-grunder 23cc785989 Implement XACKDEL 2025-11-18 10:10:48 -08:00
michael-grunder b192b0e454 Try to fix an ifdef compilation issue
Fixes #2775
2025-11-16 14:18:35 -08:00
Niels Dossche 3401462e00 Replace lagcy WRONG_PARAM_COUNT macro with its definition
Depending on the version this can either throw or not, so we don't port
over the RETURN_THROWS() part of its definition.
2025-11-16 14:07:06 -08:00
Niels Dossche 7d4fa6137c Replace legacy ZEND_WRONG_PARAM_COUNT() alias with zend_wrong_param_count() 2025-11-16 14:07:06 -08:00
Niels Dossche d24528e190 Replace legacy zval_dtor() alias with zval_ptr_dtor_nogc() 2025-11-16 14:07:06 -08:00
Niels Dossche 8e1c2789a4 Replace legacy zval_is_true() alias with zend_is_true() 2025-11-16 14:07:06 -08:00
michael-grunder c17f475caa docs: Add missing docblocs + example highlighting 2025-11-13 17:36:55 -08:00
michael-grunder 0981c2b7d7 docs: Document failover strategies. 2025-11-12 10:23:35 -08:00
michael-grunder 8ef349a2d9 docs: Document final undocumented constants. 2025-11-12 10:23:35 -08:00
michael-grunder 26cf6d9494 docs: Fully document backof strategies. 2025-11-12 10:23:35 -08:00
michael-grunder 49919b0ec5 docs: Document class constants 2025-11-12 10:23:35 -08:00