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
], '');
```
This commit is contained in:
michael-grunder
2025-08-23 14:16:46 -07:00
committed by Michael Grunder
parent b1b0c19142
commit 8d369f4d62
4 changed files with 138 additions and 49 deletions
+1
View File
@@ -137,6 +137,7 @@ class Redis_Cluster_Test extends Redis_Test {
$this->version = $info['redis_version'] ?? '0.0.0';
$this->is_keydb = $this->detectKeyDB($info);
$this->is_valkey = $this->detectValkey($info);
$this->valkey_version = $info['valkey_version'] ?? '0.0.0';
}
private function findCliExe() {
+30
View File
@@ -77,6 +77,7 @@ class Redis_Test extends TestSuite {
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
$this->is_keydb = $this->detectKeyDB($info);
$this->is_valkey = $this->detectValKey($info);
$this->valkey_version = $info['valkey_version'] ?? '0.0.0';
}
protected function haveCommand(string $cmd): bool {
@@ -90,6 +91,10 @@ class Redis_Test extends TestSuite {
return version_compare($this->version, $version) >= 0;
}
protected function minValkeyVersionCheck($version) {
return $this->is_valkey && version_compare($this->valkey_version, $version) >= 0;
}
protected function mstime() {
return round(microtime(true)*1000);
}
@@ -6913,6 +6918,31 @@ class Redis_Test extends TestSuite {
});
}
public function testGeoSearchByPolygon() {
if ( ! $this->minValkeyVersionCheck('9.0.0'))
$this->markTestSkipped();
$this->addCities('ca:cities');
$res = $this->redis->geosearch('ca:cities', '', [
-121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], '');
$this->assertEquals(['Chico'], $res);
}
public function testGeoSearchStoreByPolygon() {
if ( ! $this->minValkeyVersionCheck('9.0.0'))
$this->markTestSkipped();
$this->addCities('ca:cities');
$this->assertEquals(1, $this->redis->geosearchstore('{gk}dst', 'ca:cities', '', [
-121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], ''));
$this->assertEquals(['Chico'], $this->redis->geosearch('{gk}dst', 'Chico', 1, 'm'));
}
public function testGeoSearchStore() {
if ( ! $this->minVersionCheck('6.2.0'))
$this->markTestSkipped();
+1
View File
@@ -15,6 +15,7 @@ class TestSuite
/* Redis server version */
protected $version;
protected string $valkey_version;
protected bool $is_keydb;
protected bool $is_valkey;