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
This commit is contained in:
michael-grunder
2025-07-29 14:02:39 -07:00
committed by Michael Grunder
parent 9cae7815da
commit 286fa63064
12 changed files with 356 additions and 4 deletions
+12
View File
@@ -4196,6 +4196,18 @@ class Redis {
*/
public function xrevrange(string $key, string $end, string $start, int $count = -1): Redis|array|bool;
/**
* Add to a vector set
*
* @param string $key The vector set to add to.
* @param array $values A non-empty array of floating point values
* @param mixed $element The element to add to the vector set.
* @param array|null $options An optional options array
*
* @return Redis|int|false One if the key was added zero if not.
*/
public function vadd(string $key, array $values, mixed $element, array|null $options = null): Redis|int|false;
/**
* Truncate a STREAM key in various ways.
*