summaryrefslogtreecommitdiff
path: root/src/geo.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-06-29 10:47:07 +0200
committerantirez <antirez@gmail.com>2015-06-29 10:47:07 +0200
commitaae0a1f9cce0ced9e6aa2e76977d6db72f6b4edc (patch)
tree906cd36b04c926dbc87268399f74808e7377c740 /src/geo.c
parentf6edd0cb933c1c82c3e9e9dd33597654602a1ba4 (diff)
downloadredis-aae0a1f9cce0ced9e6aa2e76977d6db72f6b4edc.tar.gz
Geo: GEOPOS command and tests.
Diffstat (limited to 'src/geo.c')
-rw-r--r--src/geo.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/geo.c b/src/geo.c
index 37d632815..18b0efac1 100644
--- a/src/geo.c
+++ b/src/geo.c
@@ -709,3 +709,36 @@ void geoHashCommand(redisClient *c) {
}
}
}
+
+/* GEOPOS key ele1 ele2 ... eleN
+ *
+ * Returns an array of two-items arrays representing the x,y position of each
+ * element specified in the arguments. For missing elements NULL is returned. */
+void geoposCommand(redisClient *c) {
+ int j;
+
+ /* Look up the requested zset */
+ robj *zobj = NULL;
+ if ((zobj = lookupKeyReadOrReply(c, c->argv[1], shared.emptymultibulk))
+ == NULL || checkType(c, zobj, REDIS_ZSET)) return;
+
+ /* Report elements one after the other, using a null bulk reply for
+ * missing elements. */
+ addReplyMultiBulkLen(c,c->argc-2);
+ for (j = 2; j < c->argc; j++) {
+ double score;
+ if (zsetScore(zobj, c->argv[j], &score) == REDIS_ERR) {
+ addReply(c,shared.nullmultibulk);
+ } else {
+ /* Decode... */
+ double xy[2];
+ if (!decodeGeohash(score,xy)) {
+ addReply(c,shared.nullmultibulk);
+ continue;
+ }
+ addReplyMultiBulkLen(c,2);
+ addReplyDouble(c,xy[0]);
+ addReplyDouble(c,xy[1]);
+ }
+ }
+}