Add new command: GEOHASH (Redis 3.2.0).

This commit is contained in:
Daniele Alessandri
2016-05-24 15:00:02 +02:00
parent 7ef9619f5c
commit 0b6b3b2558
14 changed files with 158 additions and 0 deletions
+1
View File
@@ -157,6 +157,7 @@ use Predis\Command\CommandInterface;
* @method $this time()
* @method $this command()
* @method $this geoadd($key, $longitude, $latitude, $member)
* @method $this geohash($key, array $members)
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
+1
View File
@@ -165,6 +165,7 @@ use Predis\Profile\ProfileInterface;
* @method array time()
* @method array command()
* @method int geoadd($key, $longitude, $latitude, $member)
* @method array geohash($key, array $members)
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
+1
View File
@@ -168,6 +168,7 @@ abstract class ClusterStrategy implements StrategyInterface
/* commands performing geospatial operations */
'GEOADD' => $getKeyFromFirstArgument,
'GEOHASH' => $getKeyFromFirstArgument,
);
}
+41
View File
@@ -0,0 +1,41 @@
<?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/geohash
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class GeospatialGeoHash extends Command
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEOHASH';
}
/**
* {@inheritdoc}
*/
protected function filterArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[1])) {
$members = array_pop($arguments);
$arguments = array_merge($arguments, $members);
}
return $arguments;
}
}
@@ -161,6 +161,7 @@ class KeyPrefixProcessor implements ProcessorInterface
'HSTRLEN' => 'static::first',
'BITFIELD' => 'static::first',
'GEOADD' => 'static::first',
'GEOHASH' => 'static::first',
);
}
+1
View File
@@ -271,6 +271,7 @@ class RedisVersion320 extends RedisProfile
/* commands performing geospatial operations */
'GEOADD' => 'Predis\Command\GeospatialGeoAdd',
'GEOHASH' => 'Predis\Command\GeospatialGeoHash',
);
}
}
+1
View File
@@ -258,6 +258,7 @@ class ReplicationStrategy
'PFCOUNT' => true,
'SORT' => array($this, 'isSortReadOnly'),
'BITFIELD' => array($this, 'isBitfieldReadOnly'),
'GEOHASH' => true,
);
}
}
@@ -380,6 +380,7 @@ class PredisStrategyTest extends PredisTestCase
/* commands performing geospatial operations */
'GEOADD' => 'keys-first',
'GEOHASH' => 'keys-first',
);
if (isset($type)) {
@@ -390,6 +390,7 @@ class RedisStrategyTest extends PredisTestCase
/* commands performing geospatial operations */
'GEOADD' => 'keys-first',
'GEOHASH' => 'keys-first',
);
if (isset($type)) {
@@ -0,0 +1,102 @@
<?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 GeospatialGeoHashTest extends PredisCommandTestCase
{
/**
* {@inheritdoc}
*/
protected function getExpectedCommand()
{
return 'Predis\Command\GeospatialGeoHash';
}
/**
* {@inheritdoc}
*/
protected function getExpectedId()
{
return 'GEOHASH';
}
/**
* @group disconnected
*/
public function testFilterArguments()
{
$arguments = array('key', 'member:1', 'member:2');
$expected = array('key', 'member:1', 'member:2');
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testFilterArgumentsWithMembersAsSingleArray()
{
$arguments = array('key', array('member:1', 'member:2'));
$expected = array('key', 'member:1', 'member:2');
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponse()
{
$raw = array('sqc8b49rny0', 'sqdtr74hyu0');
$expected = array('sqc8b49rny0', 'sqdtr74hyu0');
$command = $this->getCommand();
$this->assertSame($expected, $command->parseResponse($raw));
}
/**
* @group connected
* @requiresRedisVersion >= 3.2.0
*/
public function testCommandReturnsGeoHashes()
{
$redis = $this->getClient();
$redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania');
$this->assertSame(array('sqc8b49rny0', 'sqdtr74hyu0'), $redis->geohash('Sicily', 'Palermo', 'Catania'));
}
/**
* @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->geohash('Sicily', 'Palermo');
}
}
@@ -877,6 +877,10 @@ class KeyPrefixProcessorTest extends PredisTestCase
array('key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
array('prefix:key', '13.361389', '38.115556', 'member:1', '15.087269', '37.502669', 'member:2'),
),
array('GEOHASH',
array('key', 'member:1', 'member:2'),
array('prefix:key', 'member:1', 'member:2'),
),
);
}
}
@@ -192,6 +192,7 @@ class RedisUnstableTest extends PredisProfileTestCase
151 => 'HSTRLEN',
152 => 'BITFIELD',
153 => 'GEOADD',
154 => 'GEOHASH',
);
}
}
@@ -192,6 +192,7 @@ class RedisVersion320Test extends PredisProfileTestCase
151 => 'HSTRLEN',
152 => 'BITFIELD',
153 => 'GEOADD',
154 => 'GEOHASH',
);
}
}
@@ -441,6 +441,7 @@ class ReplicationStrategyTest extends PredisTestCase
/* commands performing geospatial operations */
'GEOADD' => 'write',
'GEOHASH' => 'read',
);
if (isset($type)) {