mirror of
https://github.com/predis/predis.git
synced 2026-09-19 06:47:39 +00:00
Added tests case with FLOAT16 and BFLOAT16 vectors (#1465)
* Added tests case with FLOAT16 and BFLOAT16 vectors * Added version restriction for test * Updated version restrictions
This commit is contained in:
committed by
GitHub
parent
cbef71090b
commit
c5fdfc81ef
@@ -33,6 +33,7 @@ jobs:
|
||||
- '8.3'
|
||||
redis:
|
||||
- latest
|
||||
- edge
|
||||
|
||||
continue-on-error: ${{ matrix.php == '8.3' }}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function zpop($client, $key)
|
||||
'cas' => true, // Initialize with support for CAS operations
|
||||
'watch' => $key, // Key that needs to be WATCHed to detect changes
|
||||
'retry' => 3, // Number of retries on aborted transactions, after
|
||||
// which the client bails out with an exception.
|
||||
// which the client bails out with an exception.
|
||||
];
|
||||
|
||||
$client->transaction($options, function ($tx) use ($key, &$element) {
|
||||
|
||||
@@ -176,13 +176,13 @@ abstract class CursorBasedIterator implements Iterator
|
||||
$this->fetch();
|
||||
}
|
||||
|
||||
if ($this->elements) {
|
||||
$this->extractNext();
|
||||
} elseif ($this->cursor) {
|
||||
goto tryFetch;
|
||||
} else {
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($this->elements) {
|
||||
$this->extractNext();
|
||||
} elseif ($this->cursor) {
|
||||
goto tryFetch;
|
||||
} else {
|
||||
$this->valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ class RelayConnection extends StreamConnection
|
||||
/**
|
||||
* The Relay instance.
|
||||
*
|
||||
* @var \Relay\Relay
|
||||
* @var Relay
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
@@ -151,7 +151,7 @@ class RelayConnection extends StreamConnection
|
||||
/**
|
||||
* Creates a new instance of the client.
|
||||
*
|
||||
* @return \Relay\Relay
|
||||
* @return Relay
|
||||
*/
|
||||
private function createClient()
|
||||
{
|
||||
@@ -189,7 +189,7 @@ class RelayConnection extends StreamConnection
|
||||
/**
|
||||
* Returns the underlying client.
|
||||
*
|
||||
* @return \Relay\Relay
|
||||
* @return Relay
|
||||
*/
|
||||
public function getClient()
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ class RelayPipeline extends Pipeline
|
||||
*/
|
||||
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
/** @var \Predis\Connection\RelayConnection $connection */
|
||||
/** @var RelayConnection $connection */
|
||||
$client = $connection->getClient();
|
||||
|
||||
$throw = $this->client->getOptions()->exceptions;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
/**
|
||||
* PHPUnit constraint matching arrays with same elements even in different order.
|
||||
*/
|
||||
class ArrayHasSameValuesConstraint extends \PHPUnit\Framework\Constraint\Constraint
|
||||
class ArrayHasSameValuesConstraint extends PHPUnit\Framework\Constraint\Constraint
|
||||
{
|
||||
protected $array;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class PredisCommandTestCase extends PredisTestCase
|
||||
/**
|
||||
* Returns the expected command for tests.
|
||||
*
|
||||
* @return Command\CommandInterface|string Instance or FQCN of the expected command
|
||||
* @return CommandInterface|string Instance or FQCN of the expected command
|
||||
*/
|
||||
abstract protected function getExpectedCommand(): string;
|
||||
|
||||
@@ -36,13 +36,13 @@ abstract class PredisCommandTestCase extends PredisTestCase
|
||||
/**
|
||||
* Returns a new command instance.
|
||||
*
|
||||
* @return Command\CommandInterface
|
||||
* @return CommandInterface
|
||||
*/
|
||||
public function getCommand(): Command\CommandInterface
|
||||
public function getCommand(): CommandInterface
|
||||
{
|
||||
$command = $this->getExpectedCommand();
|
||||
|
||||
return $command instanceof Command\CommandInterface ? $command : new $command();
|
||||
return $command instanceof CommandInterface ? $command : new $command();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ use Predis\Connection;
|
||||
/**
|
||||
* Base test case class for the Predis test suite.
|
||||
*/
|
||||
abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
|
||||
abstract class PredisTestCase extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $redisServerVersion;
|
||||
protected $redisJsonVersion;
|
||||
@@ -150,7 +150,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
|
||||
* Asserts that a string matches a given regular expression.
|
||||
*
|
||||
* @throws ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public static function assertMatchesRegularExpression(string $pattern, string $string, $message = ''): void
|
||||
{
|
||||
@@ -295,7 +295,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
|
||||
if (!is_a($interface, '\Predis\Connection\NodeConnectionInterface', true)) {
|
||||
$method = __METHOD__;
|
||||
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
"Argument `\$interface` for $method() expects a type implementing Predis\Connection\NodeConnectionInterface"
|
||||
);
|
||||
}
|
||||
@@ -423,7 +423,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
|
||||
* decorates test methods while the version of the Redis server used to run
|
||||
* integration tests is retrieved directly from the server by using `INFO`.
|
||||
*
|
||||
* @throws \PHPUnit\Framework\SkippedTestError When the required Redis server version is not met
|
||||
* @throws PHPUnit\Framework\SkippedTestError When the required Redis server version is not met
|
||||
*/
|
||||
protected function checkRequiredRedisServerVersion(): void
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ use SebastianBergmann\Exporter\Exporter;
|
||||
/**
|
||||
* PHPUnit constraint to verify that a Redis command matches certain conditions.
|
||||
*/
|
||||
class RedisCommandConstraint extends \PHPUnit\Framework\Constraint\Constraint
|
||||
class RedisCommandConstraint extends PHPUnit\Framework\Constraint\Constraint
|
||||
{
|
||||
protected $commandID;
|
||||
protected $arguments;
|
||||
|
||||
@@ -225,7 +225,7 @@ class ClientTest extends PredisTestCase
|
||||
*/
|
||||
public function testConstructorWithReplicationArgument(): void
|
||||
{
|
||||
$replication = new Connection\Replication\MasterSlaveReplication();
|
||||
$replication = new MasterSlaveReplication();
|
||||
|
||||
$factory = new Connection\Factory();
|
||||
$replication->add($factory->create('tcp://host1?alias=master'));
|
||||
@@ -912,7 +912,7 @@ class ClientTest extends PredisTestCase
|
||||
*/
|
||||
public function testGetClientByMethodSupportsSelectingConnectionByCommand(): void
|
||||
{
|
||||
$command = \Predis\Command\RawCommand::create('GET', 'key');
|
||||
$command = Command\RawCommand::create('GET', 'key');
|
||||
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
|
||||
|
||||
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
|
||||
@@ -1209,7 +1209,7 @@ class ClientTest extends PredisTestCase
|
||||
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382');
|
||||
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383');
|
||||
|
||||
$aggregate = new \Predis\Connection\Cluster\PredisCluster();
|
||||
$aggregate = new Connection\Cluster\PredisCluster();
|
||||
|
||||
$aggregate->add($connection1);
|
||||
$aggregate->add($connection2);
|
||||
|
||||
@@ -63,7 +63,7 @@ class HashKeyTest extends PredisTestCase
|
||||
->with('key:hash', 0, [])
|
||||
->willReturn(
|
||||
[0, [],
|
||||
]);
|
||||
]);
|
||||
|
||||
$iterator = new HashKey($client, 'key:hash');
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use Predis\Command\Argument\Search\CreateArguments;
|
||||
use Predis\Command\Argument\Search\SchemaFields\NumericField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\TagField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\TextField;
|
||||
use Predis\Command\Argument\Search\SchemaFields\VectorField;
|
||||
use Predis\Command\Redis\PredisCommandTestCase;
|
||||
|
||||
/**
|
||||
@@ -86,6 +87,32 @@ class FTCREATE_Test extends PredisCommandTestCase
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-resp3
|
||||
* @return void
|
||||
* @requiresRediSearchVersion >= 2.9.0
|
||||
*/
|
||||
public function testCreatesSearchIndexWithFloat16Vector(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$schema = [
|
||||
new VectorField('float16',
|
||||
'FLAT',
|
||||
['TYPE', 'FLOAT16', 'DIM', 768, 'DISTANCE_METRIC', 'COSINE']
|
||||
),
|
||||
new VectorField('bfloat16',
|
||||
'FLAT',
|
||||
['TYPE', 'BFLOAT16', 'DIM', 768, 'DISTANCE_METRIC', 'COSINE']
|
||||
),
|
||||
];
|
||||
|
||||
$actualResponse = $redis->ftcreate('index', $schema);
|
||||
|
||||
$this->assertEquals('OK', $actualResponse);
|
||||
}
|
||||
|
||||
public function argumentsProvider(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -63,14 +63,14 @@ class TSINFO_Test extends PredisCommandTestCase
|
||||
* @group connected
|
||||
* @group relay-resp3
|
||||
* @return void
|
||||
* @requiresRedisTimeSeriesVersion >= 1.0.0
|
||||
* @requiresRedisTimeSeriesVersion <= 1.10.13
|
||||
*/
|
||||
public function testReturnsInformationAboutGivenTimeSeries(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
$expectedResponse = ['totalSamples', 0, 'memoryUsage', 4239, 'firstTimestamp', 0, 'lastTimestamp', 0,
|
||||
'retentionTime', 60000, 'chunkCount', 1, 'chunkSize', 4096, 'chunkType', 'compressed', 'duplicatePolicy',
|
||||
'max', 'labels', [['sensor_id', '2'], ['area_id', '32']], 'sourceKey', null, 'rules', []];
|
||||
'max', 'labels', [['sensor_id', '2'], ['area_id', '32']], 'sourceKey', null, 'rules', []];
|
||||
|
||||
$arguments = (new CreateArguments())
|
||||
->retentionMsecs(60000)
|
||||
|
||||
@@ -117,7 +117,7 @@ class CommunicationExceptionTest extends PredisTestCase
|
||||
* @param int $code Exception code.
|
||||
* @param Exception $inner Inner exception.
|
||||
*
|
||||
* @return \Predis\CommunicationException
|
||||
* @return CommunicationException
|
||||
*/
|
||||
protected function createMockException(
|
||||
Connection\NodeConnectionInterface $connection,
|
||||
|
||||
@@ -36,7 +36,7 @@ class ConnectionsTest extends PredisTestCase
|
||||
*/
|
||||
public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings(): void
|
||||
{
|
||||
/** @var \Predis\Configuration\OptionsInterface */
|
||||
/** @var OptionsInterface */
|
||||
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
|
||||
|
||||
$class = get_class($this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock());
|
||||
@@ -139,7 +139,7 @@ class ConnectionsTest extends PredisTestCase
|
||||
{
|
||||
$parameters = ['database' => 5, 'password' => 'mypassword'];
|
||||
|
||||
/** @var \Predis\Configuration\OptionsInterface|\PHPUnit\Framework\MockObject\MockObject\MockObject */
|
||||
/** @var OptionsInterface|\PHPUnit\Framework\MockObject\MockObject\MockObject */
|
||||
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
|
||||
$options
|
||||
->expects($this->once())
|
||||
@@ -184,7 +184,7 @@ class ConnectionsTest extends PredisTestCase
|
||||
{
|
||||
$option = new Connections();
|
||||
|
||||
/** @var \Predis\Configuration\OptionsInterface */
|
||||
/** @var OptionsInterface */
|
||||
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
|
||||
|
||||
$callable = $this->getMockBuilder('stdClass')
|
||||
@@ -211,7 +211,7 @@ class ConnectionsTest extends PredisTestCase
|
||||
|
||||
$option = new Connections();
|
||||
|
||||
/** @var \Predis\Configuration\OptionsInterface */
|
||||
/** @var OptionsInterface */
|
||||
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
|
||||
|
||||
$option->filter($options, new stdClass());
|
||||
|
||||
@@ -336,7 +336,7 @@ class RedisClusterTest extends PredisTestCase
|
||||
);
|
||||
|
||||
// TODO: I'm not sure about mocking a protected method, but it'll do for now
|
||||
/** @var Connection\Cluster\RedisCluster|MockObject */
|
||||
/** @var RedisCluster|MockObject */
|
||||
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster')
|
||||
->onlyMethods(['getRandomConnection'])
|
||||
->setConstructorArgs([$factory])
|
||||
@@ -716,7 +716,7 @@ class RedisClusterTest extends PredisTestCase
|
||||
->willReturn($connection4);
|
||||
|
||||
// TODO: I'm not sure about mocking a protected method, but it'll do for now
|
||||
/** @var Connection\Cluster\RedisCluster|MockObject */
|
||||
/** @var RedisCluster|MockObject */
|
||||
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster')
|
||||
->onlyMethods(['getRandomConnection'])
|
||||
->setConstructorArgs([$factory])
|
||||
@@ -823,7 +823,7 @@ class RedisClusterTest extends PredisTestCase
|
||||
->method('create');
|
||||
|
||||
// TODO: I'm not sure about mocking a protected method, but it'll do for now
|
||||
/** @var Connection\Cluster\RedisCluster|MockObject */
|
||||
/** @var RedisCluster|MockObject */
|
||||
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster')
|
||||
->onlyMethods(['getRandomConnection'])
|
||||
->setConstructorArgs([$factory])
|
||||
@@ -889,7 +889,7 @@ class RedisClusterTest extends PredisTestCase
|
||||
->method('create');
|
||||
|
||||
// TODO: I'm not sure about mocking a protected method, but it'll do for now
|
||||
/** @var Connection\Cluster\RedisCluster|MockObject */
|
||||
/** @var RedisCluster|MockObject */
|
||||
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster')
|
||||
->onlyMethods(['getRandomConnection'])
|
||||
->setConstructorArgs([$factory])
|
||||
@@ -1427,7 +1427,7 @@ class RedisClusterTest extends PredisTestCase
|
||||
->method('create');
|
||||
|
||||
// TODO: I'm not sure about mocking a protected method, but it'll do for now
|
||||
/** @var Connection\Cluster\RedisCluster|MockObject */
|
||||
/** @var RedisCluster|MockObject */
|
||||
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\RedisCluster')
|
||||
->onlyMethods(['getRandomConnection'])
|
||||
->setConstructorArgs([$factory])
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
|
||||
if (file_exists(__DIR__ . '/../autoload.php')) {
|
||||
require __DIR__ . '/../autoload.php';
|
||||
} elseif (@include('Predis/Autoloader.php')) {
|
||||
} elseif (@include ('Predis/Autoloader.php')) {
|
||||
Predis\Autoloader::register();
|
||||
} else {
|
||||
exit('ERROR: Unable to find a suitable mean to register Predis\Autoloader.');
|
||||
|
||||
Reference in New Issue
Block a user