MCPcopy Create free account
hub / github.com/F-Stack/f-stack / geodistCommand

Function geodistCommand

app/redis-6.2.6/src/geo.c:966–998  ·  view source on GitHub ↗

GEODIST key ele1 ele2 [unit] * * Return the distance, in meters by default, otherwise according to "unit", * between points ele1 and ele2. If one or more elements are missing NULL * is returned. */

Source from the content-addressed store, hash-verified

964 * between points ele1 and ele2. If one or more elements are missing NULL
965 * is returned. */
966void geodistCommand(client *c) {
967 double to_meter = 1;
968
969 /* Check if there is the unit to extract, otherwise assume meters. */
970 if (c->argc == 5) {
971 to_meter = extractUnitOrReply(c,c->argv[4]);
972 if (to_meter < 0) return;
973 } else if (c->argc > 5) {
974 addReplyErrorObject(c,shared.syntaxerr);
975 return;
976 }
977
978 /* Look up the requested zset */
979 robj *zobj = NULL;
980 if ((zobj = lookupKeyReadOrReply(c, c->argv[1], shared.null[c->resp]))
981 == NULL || checkType(c, zobj, OBJ_ZSET)) return;
982
983 /* Get the scores. We need both otherwise NULL is returned. */
984 double score1, score2, xyxy[4];
985 if (zsetScore(zobj, c->argv[2]->ptr, &score1) == C_ERR ||
986 zsetScore(zobj, c->argv[3]->ptr, &score2) == C_ERR)
987 {
988 addReplyNull(c);
989 return;
990 }
991
992 /* Decode & compute the distance. */
993 if (!decodeGeohash(score1,xyxy) || !decodeGeohash(score2,xyxy+2))
994 addReplyNull(c);
995 else
996 addReplyDoubleDistance(c,
997 geohashGetDistance(xyxy[0],xyxy[1],xyxy[2],xyxy[3]) / to_meter);
998}

Callers

nothing calls this directly

Calls 9

extractUnitOrReplyFunction · 0.85
addReplyErrorObjectFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
zsetScoreFunction · 0.85
addReplyNullFunction · 0.85
decodeGeohashFunction · 0.85
addReplyDoubleDistanceFunction · 0.85
geohashGetDistanceFunction · 0.85

Tested by

no test coverage detected