Add new command: GEODIST (Redis 3.2.0).

This commit is contained in:
Daniele Alessandri
2016-05-24 16:23:07 +02:00
parent c4e0044269
commit b2284d015f
14 changed files with 131 additions and 0 deletions
+1
View File
@@ -159,6 +159,7 @@ use Predis\Command\CommandInterface;
* @method $this geoadd($key, $longitude, $latitude, $member)
* @method $this geohash($key, array $members)
* @method $this geopos($key, array $members)
* @method $this geodist($key, $member1, $member2, $unit = null)
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
+1
View File
@@ -167,6 +167,7 @@ use Predis\Profile\ProfileInterface;
* @method int geoadd($key, $longitude, $latitude, $member)
* @method array geohash($key, array $members)
* @method array geopos($key, array $members)
* @method string geodist($key, $member1, $member2, $unit = null)
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
+1
View File
@@ -170,6 +170,7 @@ abstract class ClusterStrategy implements StrategyInterface
'GEOADD' => $getKeyFromFirstArgument,
'GEOHASH' => $getKeyFromFirstArgument,
'GEOPOS' => $getKeyFromFirstArgument,
'GEODIST' => $getKeyFromFirstArgument,
);
}
+28
View File
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command;
/**
* @link http://redis.io/commands/geodist
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class GeospatialGeoDist extends Command
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEODIST';
}
}
@@ -163,6 +163,7 @@ class KeyPrefixProcessor implements ProcessorInterface
'GEOADD' => 'static::first',
'GEOHASH' => 'static::first',
'GEOPOS' => 'static::first',
'GEODIST' => 'static::first',
);
}
+1
View File
@@ -273,6 +273,7 @@ class RedisVersion320 extends RedisProfile
'GEOADD' => 'Predis\Command\GeospatialGeoAdd',
'GEOHASH' => 'Predis\Command\GeospatialGeoHash',
'GEOPOS' => 'Predis\Command\GeospatialGeoPos',
'GEODIST' => 'Predis\Command\GeospatialGeoDist',
);
}
}
+1
View File
@@ -260,6 +260,7 @@ class ReplicationStrategy
'BITFIELD' => array($this, 'isBitfieldReadOnly'),
'GEOHASH' => true,
'GEOPOS' => true,
'GEODIST' => true,
);
}
}
@@ -382,6 +382,7 @@ class PredisStrategyTest extends PredisTestCase
'GEOADD' => 'keys-first',
'GEOHASH' => 'keys-first',
'GEOPOS' => 'keys-first',
'GEODIST' => 'keys-first',
);
if (isset($type)) {
@@ -392,6 +392,7 @@ class RedisStrategyTest extends PredisTestCase
'GEOADD' => 'keys-first',
'GEOHASH' => 'keys-first',
'GEOPOS' => 'keys-first',
'GEODIST' => 'keys-first',
);
if (isset($type)) {
@@ -0,0 +1,88 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command;
/**
* @group commands
* @group realm-geospatial
*/
class GeospatialGeoDistTest extends PredisCommandTestCase
{
/**
* {@inheritdoc}
*/
protected function getExpectedCommand()
{
return 'Predis\Command\GeospatialGeoDist';
}
/**
* {@inheritdoc}
*/
protected function getExpectedId()
{
return 'GEODIST';
}
/**
* @group disconnected
*/
public function testFilterArguments()
{
$arguments = array('key', 'member:1', 'member:2', 'km');
$expected = array('key', 'member:1', 'member:2', 'km');
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponse()
{
$raw = array('103.31822459492736');
$expected = array('103.31822459492736');
$command = $this->getCommand();
$this->assertSame($expected, $command->parseResponse($raw));
}
/**
* @group connected
* @requiresRedisVersion >= 3.2.0
*/
public function testCommandReturnsGeoDistance()
{
$redis = $this->getClient();
$redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania');
$this->assertSame('166.2742', $redis->geodist('Sicily', 'Palermo', 'Catania', 'km'));
}
/**
* @group connected
* @requiresRedisVersion >= 3.2.0
* @expectedException \Predis\Response\ServerException
* @expectedExceptionMessage Operation against a key holding the wrong kind of value
*/
public function testThrowsExceptionOnWrongType()
{
$redis = $this->getClient();
$redis->lpush('Sicily', 'Palermo');
$redis->geodist('Sicily', 'Palermo', 'Catania');
}
}
@@ -885,6 +885,10 @@ class KeyPrefixProcessorTest extends PredisTestCase
array('key', 'member:1', 'member:2'),
array('prefix:key', 'member:1', 'member:2'),
),
array('GEODIST',
array('key', 'member:1', 'member:2', 'km'),
array('prefix:key', 'member:1', 'member:2', 'km'),
),
);
}
}
@@ -194,6 +194,7 @@ class RedisUnstableTest extends PredisProfileTestCase
153 => 'GEOADD',
154 => 'GEOHASH',
155 => 'GEOPOS',
156 => 'GEODIST',
);
}
}
@@ -194,6 +194,7 @@ class RedisVersion320Test extends PredisProfileTestCase
153 => 'GEOADD',
154 => 'GEOHASH',
155 => 'GEOPOS',
156 => 'GEODIST',
);
}
}
@@ -443,6 +443,7 @@ class ReplicationStrategyTest extends PredisTestCase
'GEOADD' => 'write',
'GEOHASH' => 'read',
'GEOPOS' => 'read',
'GEODIST' => 'read',
);
if (isset($type)) {