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. */
| 964 | * between points ele1 and ele2. If one or more elements are missing NULL |
| 965 | * is returned. */ |
| 966 | void 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 | } |
nothing calls this directly
no test coverage detected