3294 Commits

Author SHA1 Message Date
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
b1b0c19142 Implement DELIFEQ command
Implement the command and add a test.
2025-08-24 06:37:28 -07:00
Jacob Brown
b0ba827be2 Fixing segfault in cluster_update_slot
When the slot's->slaves was null, it was dereferencing null, causing
segfault.
This happens in weird scenario when some of the nodes in cluster are
down or having changed IP addresses without knowing about it.
2025-08-22 11:59:38 -07:00
Michael Grunder
8685c49c70 Use continue not break if we get a NULL node
This is likely to never happen but just skipping NULL nodes is better than aborting the reset.

Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
2025-08-21 08:53:51 -07:00
michael-grunder
f4ec5e2bb0 Use ZEND_STRL instead of literal, len 2025-08-21 08:53:51 -07:00
michael-grunder
a0621555b5 Reduce to < 80 chars 2025-08-21 08:53:51 -07:00
michael-grunder
03837f0230 Remove pointless casts
You never have to explicitly cast between `void*` and any other pointer
type.
2025-08-21 08:53:51 -07:00
michael-grunder
7769194757 Change int flags to zend_bool since we only use them as booleans 2025-08-21 08:53:51 -07:00
michael-grunder
9802fc0e46 Rework REDIS_SAVE_CALLBACK to be a function. 2025-08-21 08:53:51 -07:00
michael-grunder
58e1a04f76 Remove wrapper macro which hides branching logic
This wrapper macro implicitly defines an `} else {` block but this is
not clear at the callsite which obsures what is actually going on.

There's no real advantage to the wrapping macro. Instead just call the
underlying macro in an explicit else branch.
2025-08-21 08:53:51 -07:00
michael-grunder
8f0931bbed Rework REDIS_PROCESS_REQUEST to be a function. 2025-08-21 08:53:51 -07:00
michael-grunder
7c953d458b Remove dead legacy code. 2025-08-21 08:53:51 -07:00
michael-grunder
950d2bc79d Rework REDIS_PROCESS_KW_CMD as a function 2025-08-21 08:53:51 -07:00
michael-grunder
601ebbff2b Rework REDIS_PROCESS_CMD into a static function 2025-08-21 08:53:51 -07:00
michael-grunder
c3a7163108 Rework CLUSTER_RESET_MULTI to be a static function 2025-08-21 08:53:51 -07:00
michael-grunder
b004051499 Rewowrk CLUSTER_FREE_QUEUE as a static function 2025-08-21 08:53:51 -07:00
michael-grunder
fae89fa992 Remove dead macro CLUSTER_BUILD_CMD 2025-08-21 08:53:51 -07:00
michael-grunder
f880e1f727 Make CLUSTER_ENQUEUE_RESPONSE a static function 2025-08-21 08:53:51 -07:00
michael-grunder
b90e27f285 Rework CLUSTER_PROCESS_KW_CMD to be a small wrapper macro + function
This commit is similar to the last one reworking processing keyword
commands to work to use a function instead of a big multiline macro.
2025-08-21 08:53:51 -07:00
michael-grunder
1db3908914 Rework CLUSTER_PROCESS_CMD to use an underlying function
In theory this should reduce PhpRedis' code size and likely doesn't
affect performance in a measurable way.
2025-08-21 08:53:51 -07:00
michael-grunder
d564e8cf3c Fix dead assignment 2025-08-21 08:53:51 -07:00
michael-grunder
8be2306e4f Fix several issues surfaced by gcc -fanzlyze
Mostly null pointer derefs or use of uninitialized values. Some were
probably false positives since hte analyzer can't fully reason about how
the zend internals use `zval` structs but the fixes don't really have
any downside.
2025-08-15 07:52:21 -07:00
Michael Grunder
b83981aaeb Rework HEXPIRE test inclusion + bump Valkey (#2684)
* Rework `HEXPIRE` test inclusion + bump Valkey

* Add a little `haveCommand` helper which uses `COMMAND INFO` to check
  if a given server has a specific command. This way when we bump valkey
  to an official release that supports the commands we will start
  testing.
* Bump Valkey from 7.2.5 to 8.1.3 which is much newer.

* Rework `haveCommand` to explicitly check for the command name

COMMAND INFO will return the command name as one of the first bits of
data so we can check for it that way.

* Fix incorrect logic
2025-08-06 10:08:49 -07:00
michael-grunder
6e5faf4226 Refactor EVAL[SHA] command and add a regression test
* We can make the code simpler by using `zend_empty_array` when no args
  are passed as well as the new argument parsing macros and newer internal
  redis command appending functions that take zend strings.

* Add a regression test for when we execute `EVAL[SHA]` with arguments
  but do not send any keys. This was causing UB in RedisCluster (#2681).
2025-08-05 13:20:36 -07:00
michael-grunder
f61e8cd7ba Fix RedisCluster segfault
We were previously only picking a random slot if the user didn't pass
any arguments at all whereas we want to pick a random slot if they don't
pass any *keys*.

This change just universally picks a random slot at the beginning and
then if any keys are processed those keys will override the random
selection.

Fixes #2681
2025-08-05 08:28:43 -07:00
Pavlo Yatsukhnenko
334937cb98 Add PHP 8.5 to CI 2025-08-04 07:39:25 -07:00
michael-grunder
d1d690053f Implement VSIM command
This command is similar to `VADD` in that it's pretty simple but allows
for a great many options.

In it's most basic form:

```php
// To get similarity of a different element
$redis->vsim('myvec', 'some-element');

// To get similarity for a vector of scores
```

As seen above the method attempts to infer element or vector from the
argument passed to $member`. However, since we do serialize the member
when doing `ELE` mode, the user can also specify `ELE` explicitly in the
options array to force an `ELE` search sending serialized values.

```php
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$redis->vsim('myvec', [3.14, 2.71], ['ELE']);
```

See #2543
2025-07-31 08:30:47 -07:00
michael-grunder
286fa63064 Implement VADD command
This is for Redis 8.0's vector sets.

The command itself can be quite complex with all of the various options but
pretty simple using all defaults.

```php
$redis->vadd('myvec', [3.14, 2.17], 'myelement');
```

The implementation takes a default argument `$options` which can be an array in
order to specify the myriad of other knobs users can send. We just do a bit of
validation on inputs (e.g. certain numeric options must be positive) and make
sure the command is constructed in a valid way (e.g. REDUCE <dim> must come
before the floating point values).

By default we deliver `FP32` blobs but allow the user to send `VALUES` in the
options array which will cause PhpRedis to send N individual values. Sending
values is slower but might be nice for debugging (e.g. watching monitor)

See #2543
2025-07-31 00:57:28 -07:00
Wyatt OʼDay
9cae7815da Make changes requested by @yatsukhnenko 2025-07-30 09:37:32 -07:00
Wyatt OʼDay
d18db84c68 Link to the correct header 2025-07-30 09:37:32 -07:00
Wyatt OʼDay
1e6f5477cb Fix compiling with PHP 8.5.0 alpha3 and newer 2025-07-30 09:37:32 -07:00
michael-grunder
ca80ee0e67 Fix passing NULL for hash expiry argument
The stubs specify `?string $mode = NULL` but we were using `Z_PARAM_STR`
causing an arginfo mismatch.

Fixes #2674
2025-07-28 10:33:49 -07:00
michael-grunder
340f23b082 Fix an off-by-one length calculation error.
We want `buf + 1`, `len - 1`.
2025-07-26 22:24:43 -07:00
Pavlo Yatsukhnenko
a6922a07fe Update redis_commands.c
Co-authored-by: Michael Grunder <michael.grunder@gmail.com>
2025-07-24 09:38:01 -07:00
Pavlo Yatsukhnenko
6b2f088d49 Fix hset fields handling 2025-07-24 09:38:01 -07:00
Pavlo Yatsukhnenko
7805da7542 Fix HSetEx expiry argument handling 2025-07-24 09:08:33 -07:00
michael-grunder
2acab399cb Fix the echo liveness check when in sentinel mode.
The current echo liveness check was doing one big complex conditional
trying to incorporate both sentinel's expected ERR no such command
response and non-sentinel's actual bulk reply to ECHO.

This commit refactors the logic to check the echo response into a little
helper with different logic depending on whether or not we're connected
to a sentinel.

Additionally, we add a test to verify that we are in fact reusing
persistent connections when the user requests a persistent connection
with `RedisSentinel`.

Fixes #2148
2025-07-18 08:43:22 -07:00
michael-grunder
75acbb0984 Remove unused macros + simplify some logic 2025-07-18 08:43:22 -07:00
Michael Grunder
ce5b0facc2 Implement HGETEX, HSETEX, HGETDEL, and refactor HMGET (#2667)
* Rework HMGET and implement HGETEX

Instead of using a bespoke NULL terminated `zval**` array for the
context array we can use a `HashTable`. This might be a tiny bit more
expensive but Zend hashtables are quite efficient and this should also
be less error prone.

* Rework our `HashTable` context array to store keys

Instead of sending an array of values we can instead add the fields as
keys to our context array. That way when we combine the keys with the
Redis provided values we can do it in-place and then just give the
HashTable to the user to then do with what they want.

* Implement HGETDEL command.

* Fix edge cases to abide by legacy behavior.

Previously we coerced integer strings into integer keys when zipping
`HMGET` responses. This commit adds logic so we continue to do this and
do not change semantics.

* Implement `HGETDEL` and `HGETEX` for `RedisCluster`.

This commit implements the new commands and reworks the `HMGET` reply
handler to use the new context `HashTable`.

* Fix an edge case where we get zero multiblk elements

* Tests for `HGETEX` and `HGETDEL`

* Minor logic improvement

We don't need to check if `c->reply_len > 0` in the last else block
since we have already determined it must be.

* Implement `HSETEX` for `Redis` and `RedisCluster`

* Use `zval_get_tmp_string` ro populating non-long keys
2025-07-16 16:46:09 -07:00
Anton Smirnov
8dada174c4 Add an INI setting returning 5.x legacy behavior -- readonly session on lock failure 2025-07-09 20:07:57 -07:00
michael-grunder
152fdda9b1 Fix double -> int truncation warning 2025-05-08 09:19:12 -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
7350768cd9 Implement several hash expiration commands
Commands implemented:

`H[P]EXPIRE`
`H[P]TTL`
`H[P]EXPIREAT`
`H[P]EXPIRETIME`
`HPERSIST`
2025-05-07 08:16:14 -07:00
michael-grunder
593ba012ac Check for dragonfly_version in HELLO response
DragonflyDB will report to be Redis but also include `dragonfly_version`
in the hello response, which we can use to identify the fork.

Also fix parsing of the `HELLO` response for `serverName()` and
`serverVersion()`. Starting in Redis 8.0 there seem to always be modules
running, which the previous function was not expecting or parsing.
2025-05-05 09:31:11 -07:00
michael-grunder
b48aa0d471 Fix an unused variable warning 2025-04-20 10:18:30 -07:00
AkameOuO
b7a97e5ec3 Update README.md 2025-04-20 09:38:11 -07:00
Michael Giuffrida
bfbab89258 Broaden return type for Redis::hGetAll
`Redis::hGetAll()` returns an array indexed by `string`s and/or `int`s depending on the values in the hash set.

The function in the PHP stub was annotated as though the array were keyed only by strings, which is tighter than reality.
2025-04-20 09:03:22 -07:00
Rory
3c64b33ffe Fix SIGABRT in PHP 8.4 with RedisArray
Same fix as 6e5360d1, with PHP switching from `ZEND_ASSUME` to `ZEND_ASSERT` in zend_hash_str_update_ptr.

Fixes #2648
2025-04-08 09:38:45 -07:00
Jakub Onderka
614b86e457 New macros REDIS_RESPONSE_ERROR and REDIS_RETURN_ZVAL
Deduplicate code that is used in many methods. Also optimise adding new element to array in pipeline mode and returning zval in atomic mode
2025-04-05 09:05:26 -07:00
michael-grunder
5208818e8c We can use zval_get_tmp_string here 2025-04-02 13:02:52 -07:00