diff options
author | michael-grunder <michael.grunder@gmail.com> | 2016-06-08 22:28:57 +0300 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2016-06-08 22:28:57 +0300 |
commit | 3a33700c28679f5a42cdd168cddb6cc7d4776e0a (patch) | |
tree | 357b26eae4f0aa689d863547c1dccee5c4a4bbad | |
parent | f4bf4e306a98f89034ea9892392a1f15f6272cab (diff) |
Cluster geo commands and a generic so cluster and redis tests both work
-rw-r--r-- | redis_cluster.c | 35 | ||||
-rw-r--r-- | redis_cluster.h | 6 | ||||
-rw-r--r-- | tests/RedisClusterTest.php | 5 | ||||
-rw-r--r-- | tests/RedisTest.php | 18 |
4 files changed, 57 insertions, 7 deletions
diff --git a/redis_cluster.c b/redis_cluster.c index 1bdbc068..42809ae7 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -218,6 +218,12 @@ zend_function_entry redis_cluster_functions[] = { PHP_ME(RedisCluster, pubsub, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, script, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, slowlog, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, geoadd, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, geohash, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, geopos, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, geodist, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, georadius, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, georadiusbymember, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -2813,6 +2819,35 @@ PHP_METHOD(RedisCluster, slowlog) { } /* }}} */ +/* {{{ proto int RedisCluster::geoadd(string key, float long float lat string mem, ...) */ +PHP_METHOD(RedisCluster, geoadd) { + CLUSTER_PROCESS_KW_CMD("GEOADD", redis_key_varval_cmd, cluster_long_resp, 0); +} + +/* {{{ proto array RedisCluster::geohash(string key, string mem1, [string mem2...]) */ +PHP_METHOD(RedisCluster, geohash) { + CLUSTER_PROCESS_KW_CMD("GEOHASH", redis_key_varval_cmd, cluster_mbulk_raw_resp, 1); +} + +/* {{{ proto array RedisCluster::geopos(string key, string mem1, [string mem2...]) */ +PHP_METHOD(RedisCluster, geopos) { + CLUSTER_PROCESS_KW_CMD("GEOPOS", redis_key_varval_cmd, cluster_variant_resp, 1); +} + +/* {{{ proto array RedisCluster::geodist(string key, string mem1, string mem2 [string unit]) */ +PHP_METHOD(RedisCluster, geodist) { + CLUSTER_PROCESS_CMD(geodist, cluster_dbl_resp, 1); +} + +/* {{{ proto array RedisCluster::georadius() }}} */ +PHP_METHOD(RedisCluster, georadius) { + CLUSTER_PROCESS_CMD(georadius, cluster_variant_resp, 1); +} + +/* {{{ proto array RedisCluster::georadiusbymember() }}} */ +PHP_METHOD(RedisCluster, georadiusbymember) { + CLUSTER_PROCESS_CMD(georadiusbymember, cluster_variant_resp, 1) +} /* {{{ proto array RedisCluster::role(string key) * proto array RedisCluster::role(array host_port) */ diff --git a/redis_cluster.h b/redis_cluster.h index 8693d0d4..6f2a7ca3 100644 --- a/redis_cluster.h +++ b/redis_cluster.h @@ -239,6 +239,12 @@ PHP_METHOD(RedisCluster, pubsub); PHP_METHOD(RedisCluster, script); PHP_METHOD(RedisCluster, slowlog); PHP_METHOD(RedisCluster, command); +PHP_METHOD(RedisCluster, geoadd); +PHP_METHOD(RedisCluster, geohash); +PHP_METHOD(RedisCluster, geopos); +PHP_METHOD(RedisCluster, geodist); +PHP_METHOD(RedisCluster, georadius); +PHP_METHOD(RedisCluster, georadiusbymember); /* SCAN and friends */ PHP_METHOD(RedisCluster, scan); diff --git a/tests/RedisClusterTest.php b/tests/RedisClusterTest.php index f1cbdd25..ffe17230 100644 --- a/tests/RedisClusterTest.php +++ b/tests/RedisClusterTest.php @@ -501,5 +501,10 @@ class Redis_Cluster_Test extends Redis_Test { $this->redis->rpush('mylist', 'A','B','C','D'); $this->assertEquals($this->redis->lrange('mylist', 0, -1), Array('A','B','C','D')); } + + protected function rawCommandArray($key, $args) { + array_unshift($args, $key); + return call_user_func_array(Array($this->redis, 'rawCommand'), $args); + } } ?> diff --git a/tests/RedisTest.php b/tests/RedisTest.php index e69fac41..7772244f 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -4769,6 +4769,10 @@ class Redis_Test extends TestSuite // GEO* command tests // + protected function rawCommandArray($key, $args) { + return call_user_func_array(Array($this->redis, 'rawCommand'), $args); + } + protected function addCities($key) { $this->redis->del($key); foreach ($this->cities as $city => $longlat) { @@ -4851,7 +4855,7 @@ class Redis_Test extends TestSuite $realopts[] = $sortopt; } - $ret1 = call_user_func_array(Array($this->redis, 'rawcommand'), $realargs); + $ret1 = $this->rawCommandArray('gk', $realargs); if ($cmd == 'georadius') { $ret2 = $this->redis->$cmd('gk', $lng, $lat, 500, 'mi', $realopts); } else { @@ -4873,25 +4877,25 @@ class Redis_Test extends TestSuite public function testGeoPos() { $this->addCities('gk'); - $this->assertEquals($this->redis->geopos('gk', 'Chico', 'Sacramento'), $this->redis->rawCommand('geopos', 'gk', 'Chico', 'Sacramento')); - $this->assertEquals($this->redis->geopos('gk', 'Cupertino'), $this->redis->rawCommand('geopos', 'gk', 'Cupertino')); + $this->assertEquals($this->redis->geopos('gk', 'Chico', 'Sacramento'), $this->rawCommandArray('gk', Array('geopos', 'gk', 'Chico', 'Sacramento'))); + $this->assertEquals($this->redis->geopos('gk', 'Cupertino'), $this->rawCommandArray('gk', Array('geopos', 'gk', 'Cupertino'))); } public function testGeoHash() { $this->addCities('gk'); - $this->assertEquals($this->redis->geohash('gk', 'Chico', 'Sacramento'), $this->redis->rawCommand('geohash', 'gk', 'Chico', 'Sacramento')); - $this->assertEquals($this->redis->geohash('gk', 'Chico'), $this->redis->rawCommand('geohash', 'gk', 'Chico')); + $this->assertEquals($this->redis->geohash('gk', 'Chico', 'Sacramento'), $this->rawCommandArray('gk', Array('geohash', 'gk', 'Chico', 'Sacramento'))); + $this->assertEquals($this->redis->geohash('gk', 'Chico'), $this->rawCommandArray('gk', Array('geohash', 'gk', 'Chico'))); } public function testGeoDist() { $this->addCities('gk'); $r1 = $this->redis->geodist('gk', 'Chico', 'Cupertino'); - $r2 = $this->redis->rawCommand('geodist', 'gk', 'Chico', 'Cupertino'); + $r2 = $this->rawCommandArray('gk', Array('geodist', 'gk', 'Chico', 'Cupertino')); $this->assertEquals(round($r1, 8), round($r2, 8)); $r1 = $this->redis->geodist('gk', 'Chico', 'Cupertino', 'km'); - $r2 = $this->redis->rawCommand('geodist', 'gk', 'Chico', 'Cupertino', 'km'); + $r2 = $this->rawCommandArray('gk', Array('geodist', 'gk', 'Chico', 'Cupertino', 'km')); $this->assertEquals(round($r1, 8), round($r2, 8)); } |