Skip to content

Commit 3a33700

Browse files
Cluster geo commands and a generic so cluster and redis tests both work
1 parent f4bf4e3 commit 3a33700

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

redis_cluster.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ zend_function_entry redis_cluster_functions[] = {
218218
PHP_ME(RedisCluster, pubsub, NULL, ZEND_ACC_PUBLIC)
219219
PHP_ME(RedisCluster, script, NULL, ZEND_ACC_PUBLIC)
220220
PHP_ME(RedisCluster, slowlog, NULL, ZEND_ACC_PUBLIC)
221+
PHP_ME(RedisCluster, geoadd, NULL, ZEND_ACC_PUBLIC)
222+
PHP_ME(RedisCluster, geohash, NULL, ZEND_ACC_PUBLIC)
223+
PHP_ME(RedisCluster, geopos, NULL, ZEND_ACC_PUBLIC)
224+
PHP_ME(RedisCluster, geodist, NULL, ZEND_ACC_PUBLIC)
225+
PHP_ME(RedisCluster, georadius, NULL, ZEND_ACC_PUBLIC)
226+
PHP_ME(RedisCluster, georadiusbymember, NULL, ZEND_ACC_PUBLIC)
221227
{NULL, NULL, NULL}
222228
};
223229

@@ -2813,6 +2819,35 @@ PHP_METHOD(RedisCluster, slowlog) {
28132819
}
28142820
/* }}} */
28152821

2822+
/* {{{ proto int RedisCluster::geoadd(string key, float long float lat string mem, ...) */
2823+
PHP_METHOD(RedisCluster, geoadd) {
2824+
CLUSTER_PROCESS_KW_CMD("GEOADD", redis_key_varval_cmd, cluster_long_resp, 0);
2825+
}
2826+
2827+
/* {{{ proto array RedisCluster::geohash(string key, string mem1, [string mem2...]) */
2828+
PHP_METHOD(RedisCluster, geohash) {
2829+
CLUSTER_PROCESS_KW_CMD("GEOHASH", redis_key_varval_cmd, cluster_mbulk_raw_resp, 1);
2830+
}
2831+
2832+
/* {{{ proto array RedisCluster::geopos(string key, string mem1, [string mem2...]) */
2833+
PHP_METHOD(RedisCluster, geopos) {
2834+
CLUSTER_PROCESS_KW_CMD("GEOPOS", redis_key_varval_cmd, cluster_variant_resp, 1);
2835+
}
2836+
2837+
/* {{{ proto array RedisCluster::geodist(string key, string mem1, string mem2 [string unit]) */
2838+
PHP_METHOD(RedisCluster, geodist) {
2839+
CLUSTER_PROCESS_CMD(geodist, cluster_dbl_resp, 1);
2840+
}
2841+
2842+
/* {{{ proto array RedisCluster::georadius() }}} */
2843+
PHP_METHOD(RedisCluster, georadius) {
2844+
CLUSTER_PROCESS_CMD(georadius, cluster_variant_resp, 1);
2845+
}
2846+
2847+
/* {{{ proto array RedisCluster::georadiusbymember() }}} */
2848+
PHP_METHOD(RedisCluster, georadiusbymember) {
2849+
CLUSTER_PROCESS_CMD(georadiusbymember, cluster_variant_resp, 1)
2850+
}
28162851

28172852
/* {{{ proto array RedisCluster::role(string key)
28182853
* proto array RedisCluster::role(array host_port) */

redis_cluster.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ PHP_METHOD(RedisCluster, pubsub);
239239
PHP_METHOD(RedisCluster, script);
240240
PHP_METHOD(RedisCluster, slowlog);
241241
PHP_METHOD(RedisCluster, command);
242+
PHP_METHOD(RedisCluster, geoadd);
243+
PHP_METHOD(RedisCluster, geohash);
244+
PHP_METHOD(RedisCluster, geopos);
245+
PHP_METHOD(RedisCluster, geodist);
246+
PHP_METHOD(RedisCluster, georadius);
247+
PHP_METHOD(RedisCluster, georadiusbymember);
242248

243249
/* SCAN and friends */
244250
PHP_METHOD(RedisCluster, scan);

tests/RedisClusterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,5 +501,10 @@ public function testRawCommand() {
501501
$this->redis->rpush('mylist', 'A','B','C','D');
502502
$this->assertEquals($this->redis->lrange('mylist', 0, -1), Array('A','B','C','D'));
503503
}
504+
505+
protected function rawCommandArray($key, $args) {
506+
array_unshift($args, $key);
507+
return call_user_func_array(Array($this->redis, 'rawCommand'), $args);
508+
}
504509
}
505510
?>

tests/RedisTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,10 @@ public function testPFCommands() {
47694769
// GEO* command tests
47704770
//
47714771

4772+
protected function rawCommandArray($key, $args) {
4773+
return call_user_func_array(Array($this->redis, 'rawCommand'), $args);
4774+
}
4775+
47724776
protected function addCities($key) {
47734777
$this->redis->del($key);
47744778
foreach ($this->cities as $city => $longlat) {
@@ -4851,7 +4855,7 @@ public function genericGeoRadiusTest($cmd) {
48514855
$realopts[] = $sortopt;
48524856
}
48534857

4854-
$ret1 = call_user_func_array(Array($this->redis, 'rawcommand'), $realargs);
4858+
$ret1 = $this->rawCommandArray('gk', $realargs);
48554859
if ($cmd == 'georadius') {
48564860
$ret2 = $this->redis->$cmd('gk', $lng, $lat, 500, 'mi', $realopts);
48574861
} else {
@@ -4873,25 +4877,25 @@ public function testGeoRadiusByMember() {
48734877

48744878
public function testGeoPos() {
48754879
$this->addCities('gk');
4876-
$this->assertEquals($this->redis->geopos('gk', 'Chico', 'Sacramento'), $this->redis->rawCommand('geopos', 'gk', 'Chico', 'Sacramento'));
4877-
$this->assertEquals($this->redis->geopos('gk', 'Cupertino'), $this->redis->rawCommand('geopos', 'gk', 'Cupertino'));
4880+
$this->assertEquals($this->redis->geopos('gk', 'Chico', 'Sacramento'), $this->rawCommandArray('gk', Array('geopos', 'gk', 'Chico', 'Sacramento')));
4881+
$this->assertEquals($this->redis->geopos('gk', 'Cupertino'), $this->rawCommandArray('gk', Array('geopos', 'gk', 'Cupertino')));
48784882
}
48794883

48804884
public function testGeoHash() {
48814885
$this->addCities('gk');
4882-
$this->assertEquals($this->redis->geohash('gk', 'Chico', 'Sacramento'), $this->redis->rawCommand('geohash', 'gk', 'Chico', 'Sacramento'));
4883-
$this->assertEquals($this->redis->geohash('gk', 'Chico'), $this->redis->rawCommand('geohash', 'gk', 'Chico'));
4886+
$this->assertEquals($this->redis->geohash('gk', 'Chico', 'Sacramento'), $this->rawCommandArray('gk', Array('geohash', 'gk', 'Chico', 'Sacramento')));
4887+
$this->assertEquals($this->redis->geohash('gk', 'Chico'), $this->rawCommandArray('gk', Array('geohash', 'gk', 'Chico')));
48844888
}
48854889

48864890
public function testGeoDist() {
48874891
$this->addCities('gk');
48884892

48894893
$r1 = $this->redis->geodist('gk', 'Chico', 'Cupertino');
4890-
$r2 = $this->redis->rawCommand('geodist', 'gk', 'Chico', 'Cupertino');
4894+
$r2 = $this->rawCommandArray('gk', Array('geodist', 'gk', 'Chico', 'Cupertino'));
48914895
$this->assertEquals(round($r1, 8), round($r2, 8));
48924896

48934897
$r1 = $this->redis->geodist('gk', 'Chico', 'Cupertino', 'km');
4894-
$r2 = $this->redis->rawCommand('geodist', 'gk', 'Chico', 'Cupertino', 'km');
4898+
$r2 = $this->rawCommandArray('gk', Array('geodist', 'gk', 'Chico', 'Cupertino', 'km'));
48954899
$this->assertEquals(round($r1, 8), round($r2, 8));
48964900
}
48974901

0 commit comments

Comments
 (0)