mirror of
https://github.com/predis/predis.git
synced 2026-08-31 04:35:05 +00:00
Add new command: GEOADD (Redis 3.2.0).
This commit is contained in:
@@ -157,6 +157,7 @@ use Predis\Command\CommandInterface;
|
||||
* @method $this slowlog($subcommand, $argument = null)
|
||||
* @method $this time()
|
||||
* @method $this command()
|
||||
* @method $this geoadd($key, $longitude, $latitude, $member)
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
|
||||
@@ -165,6 +165,7 @@ use Predis\Profile\ProfileInterface;
|
||||
* @method mixed slowlog($subcommand, $argument = null)
|
||||
* @method array time()
|
||||
* @method array command()
|
||||
* @method int geoadd($key, $longitude, $latitude, $member)
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
|
||||
@@ -165,6 +165,9 @@ abstract class ClusterStrategy implements StrategyInterface
|
||||
/* scripting */
|
||||
'EVAL' => array($this, 'getKeyFromScriptingCommands'),
|
||||
'EVALSHA' => array($this, 'getKeyFromScriptingCommands'),
|
||||
|
||||
/* commands performing geospatial operations */
|
||||
'GEOADD' => $getKeyFromFirstArgument,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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/geoadd
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class GeospatialGeoAdd extends Command
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'GEOADD';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function filterArguments(array $arguments)
|
||||
{
|
||||
if (count($arguments) === 2 && is_array($arguments[1])) {
|
||||
foreach (array_pop($arguments) as $item) {
|
||||
$arguments = array_merge($arguments, $item);
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,7 @@ class KeyPrefixProcessor implements ProcessorInterface
|
||||
/* ---------------- Redis 3.2 ---------------- */
|
||||
'HSTRLEN' => 'static::first',
|
||||
'BITFIELD' => 'static::first',
|
||||
'GEOADD' => 'static::first',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -268,6 +268,9 @@ class RedisVersion320 extends RedisProfile
|
||||
/* commands operating on hashes */
|
||||
'HSTRLEN' => 'Predis\Command\HashStringLength',
|
||||
'BITFIELD' => 'Predis\Command\StringBitField',
|
||||
|
||||
/* commands performing geospatial operations */
|
||||
'GEOADD' => 'Predis\Command\GeospatialGeoAdd',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,6 +395,9 @@ class PredisStrategyTest extends PredisTestCase
|
||||
/* scripting */
|
||||
'EVAL' => 'keys-script',
|
||||
'EVALSHA' => 'keys-script',
|
||||
|
||||
/* commands performing geospatial operations */
|
||||
'GEOADD' => 'keys-first',
|
||||
);
|
||||
|
||||
if (isset($type)) {
|
||||
|
||||
@@ -405,6 +405,9 @@ class RedisStrategyTest extends PredisTestCase
|
||||
/* scripting */
|
||||
'EVAL' => 'keys-script',
|
||||
'EVALSHA' => 'keys-script',
|
||||
|
||||
/* commands performing geospatial operations */
|
||||
'GEOADD' => 'keys-first',
|
||||
);
|
||||
|
||||
if (isset($type)) {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
<?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 GeospatialGeoAddTest extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCommand()
|
||||
{
|
||||
return 'Predis\Command\GeospatialGeoAdd';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedId()
|
||||
{
|
||||
return 'GEOADD';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments()
|
||||
{
|
||||
$arguments = array('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania');
|
||||
$expected = array('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania');
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsWithMembersAsSingleArray()
|
||||
{
|
||||
$arguments = array('Sicily', array(
|
||||
array('13.361389', '38.115556', 'Palermo'),
|
||||
array('15.087269', '37.502669', 'Catania'),
|
||||
));
|
||||
|
||||
$expected = array('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania');
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParseResponse()
|
||||
{
|
||||
$raw = 1;
|
||||
$expected = 1;
|
||||
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->assertSame($expected, $command->parseResponse($raw));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @requiresRedisVersion >= 3.2.0
|
||||
*/
|
||||
public function testCommandFillsSortedSet()
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo');
|
||||
$this->assertSame(array('Palermo' => '3479099956230698'), $redis->zrange('Sicily', 0, -1, 'WITHSCORES'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->geoadd('Sicily', '13.361389', '38.115556', 'Palermo');
|
||||
}
|
||||
}
|
||||
@@ -877,6 +877,10 @@ class KeyPrefixProcessorTest extends PredisTestCase
|
||||
array('key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
|
||||
array('prefix:key', 'GET', 'u8', '0', 'SET', 'u8', '0', '1'),
|
||||
),
|
||||
array('GEOADD',
|
||||
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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ class RedisUnstableTest extends PredisProfileTestCase
|
||||
150 => 'COMMAND',
|
||||
151 => 'HSTRLEN',
|
||||
152 => 'BITFIELD',
|
||||
153 => 'GEOADD',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ class RedisVersion320Test extends PredisProfileTestCase
|
||||
150 => 'COMMAND',
|
||||
151 => 'HSTRLEN',
|
||||
152 => 'BITFIELD',
|
||||
153 => 'GEOADD',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,6 +438,9 @@ class ReplicationStrategyTest extends PredisTestCase
|
||||
/* scripting */
|
||||
'EVAL' => 'write',
|
||||
'EVALSHA' => 'write',
|
||||
|
||||
/* commands performing geospatial operations */
|
||||
'GEOADD' => 'write',
|
||||
);
|
||||
|
||||
if (isset($type)) {
|
||||
|
||||
Reference in New Issue
Block a user