MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / geoposCommand

Function geoposCommand

src/geo.cpp:933–959  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

931 * Returns an array of two-items arrays representing the x,y position of each
932 * element specified in the arguments. For missing elements NULL is returned. */
933void geoposCommand(client *c) {
934 int j;
935
936 /* Look up the requested zset */
937 robj_roptr zobj = lookupKeyRead(c->db, c->argv[1]);
938 if (checkType(c, zobj, OBJ_ZSET)) return;
939
940 /* Report elements one after the other, using a null bulk reply for
941 * missing elements. */
942 addReplyArrayLen(c,c->argc-2);
943 for (j = 2; j < c->argc; j++) {
944 double score;
945 if (!zobj || zsetScore(zobj, szFromObj(c->argv[j]), &score) == C_ERR) {
946 addReplyNullArray(c);
947 } else {
948 /* Decode... */
949 double xy[2];
950 if (!decodeGeohash(score,xy)) {
951 addReplyNullArray(c);
952 continue;
953 }
954 addReplyArrayLen(c,2);
955 addReplyHumanLongDouble(c,xy[0]);
956 addReplyHumanLongDouble(c,xy[1]);
957 }
958 }
959}
960
961/* GEODIST key ele1 ele2 [unit]
962 *

Callers

nothing calls this directly

Calls 8

lookupKeyReadFunction · 0.85
checkTypeFunction · 0.85
addReplyArrayLenFunction · 0.85
zsetScoreFunction · 0.85
szFromObjFunction · 0.85
addReplyNullArrayFunction · 0.85
decodeGeohashFunction · 0.85
addReplyHumanLongDoubleFunction · 0.85

Tested by

no test coverage detected