Skip to content

Commit cd71df4

Browse files
committed
RediSearch 2.0.13 compatibility
1 parent a56cf5f commit cd71df4

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Documentation on paginated responses
1212
- Throw custom exception is client is missing
1313
- Add compatibility for Predis version 2.x
14+
- `LOAD ALL` option on Aggregate command (RediSearch `2.0.13`)
1415
- (dev) Add `make clean` to remove all generated files
1516
- (dev) Add code coverage to `\MacFJA\RediSearch\Index`
1617
- (dev) Add integration test for document insertion

src/Redis/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
abstract class AbstractCommand implements Command
3535
{
36-
public const MAX_IMPLEMENTED_VERSION = '2.0.12';
36+
public const MAX_IMPLEMENTED_VERSION = '2.0.13';
3737
public const MIN_IMPLEMENTED_VERSION = '2.0.0';
3838

3939
/**

src/Redis/Command/Aggregate.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use MacFJA\RediSearch\Redis\Command\AggregateCommand\SortByOption;
3333
use MacFJA\RediSearch\Redis\Command\AggregateCommand\WithCursor;
3434
use MacFJA\RediSearch\Redis\Command\Option\CommandOption;
35+
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
3536
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
3637
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
3738
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
@@ -58,6 +59,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
5859
'query' => new NamelessOption(null, '>=2.0.0'),
5960
'verbatim' => new FlagOption('VERBATIM', false, '>= 2.0.0'),
6061
'load' => new NumberedOption('LOAD', null, '>=2.0.0'),
62+
'loadall' => CV::allowedValues(new NamedOption('LOAD', null, '>=2.0.13'), ['ALL']),
6163
'groupby' => [],
6264
'sortby' => new SortByOption(),
6365
'apply' => [],
@@ -157,6 +159,15 @@ public function setLoad(string ...$field): self
157159
return $this;
158160
}
159161

162+
public function setLoadAll(): self
163+
{
164+
$this->options['load']->setArguments(null);
165+
$this->options['loadall']->setValue('ALL');
166+
$this->lastAdded = $this->options['loadall'];
167+
168+
return $this;
169+
}
170+
160171
public function setWithCursor(?int $count = null, ?int $maxIdle = null): self
161172
{
162173
$this->options['cursor']

src/Redis/Command/Option/NumberedOption.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function __construct(string $name, ?array $arguments = null, ?string $ver
4444
}
4545

4646
/**
47-
* @param array<float|int|string> $arguments
47+
* @param null|array<float|int|string> $arguments
4848
*/
49-
public function setArguments(array $arguments): void
49+
public function setArguments(?array $arguments): void
5050
{
5151
$this->arguments = $arguments;
5252
}

tests/Redis/Command/AggregateTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,48 @@ public function testSizeOptions(): void
121121
static::assertSame(10, $command->getSize());
122122
}
123123

124+
public function testLoadAll(): void
125+
{
126+
$command = new Aggregate('2.0.12');
127+
$command
128+
->setIndex('idx')
129+
->setQuery('@text1:"hello world"')
130+
->setLoadAll()
131+
;
132+
133+
static::assertSame([
134+
'idx',
135+
'@text1:"hello world"',
136+
], $command->getArguments());
137+
138+
$command = new Aggregate('2.0.13');
139+
$command
140+
->setIndex('idx')
141+
->setQuery('@text1:"hello world"')
142+
->setLoadAll()
143+
;
144+
145+
static::assertSame([
146+
'idx',
147+
'@text1:"hello world"',
148+
'LOAD', 'ALL',
149+
], $command->getArguments());
150+
151+
$command = new Aggregate('2.0.13');
152+
$command
153+
->setIndex('idx')
154+
->setQuery('@text1:"hello world"')
155+
->setLoad('foo', 'bar')
156+
->setLoadAll()
157+
;
158+
159+
static::assertSame([
160+
'idx',
161+
'@text1:"hello world"',
162+
'LOAD', 'ALL',
163+
], $command->getArguments());
164+
}
165+
124166
public function testFullOption(): void
125167
{
126168
$command = new Aggregate();

tests/Redis/Command/Option/NumberedOptionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public function testGetSetArguments(): void
5050
$option = new NumberedOption('FOO', ['foo']);
5151
static::assertIsArray($option->getArguments());
5252
static::assertEquals(['foo'], $option->getArguments());
53+
54+
$option = new NumberedOption('FOO', ['foo']);
55+
$option->setArguments(null);
56+
static::assertNull($option->getArguments());
57+
static::assertFalse($option->isValid());
58+
static::assertSame([], $option->render());
5359
}
5460

5561
public function testGetName(): void

0 commit comments

Comments
 (0)