Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
86c30a92
Commit
86c30a92
authored
Nov 30, 2018
by
antirez
Browse files
RESP3: geo.c updated.
parent
071da984
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/geo.c
View file @
86c30a92
...
@@ -466,7 +466,7 @@ void georadiusGeneric(client *c, int flags) {
...
@@ -466,7 +466,7 @@ void georadiusGeneric(client *c, int flags) {
/* Look up the requested zset */
/* Look up the requested zset */
robj *zobj = NULL;
robj *zobj = NULL;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
key
,
shared
.
emptymultibulk
))
==
NULL
||
if ((zobj = lookupKeyReadOrReply(c, key, shared.
null[c->resp]
)) == NULL ||
checkType(c, zobj, OBJ_ZSET)) {
checkType(c, zobj, OBJ_ZSET)) {
return;
return;
}
}
...
@@ -566,7 +566,7 @@ void georadiusGeneric(client *c, int flags) {
...
@@ -566,7 +566,7 @@ void georadiusGeneric(client *c, int flags) {
/* If no matching results, the user gets an empty reply. */
/* If no matching results, the user gets an empty reply. */
if (ga->used == 0 && storekey == NULL) {
if (ga->used == 0 && storekey == NULL) {
addReply
(
c
,
shared
.
emptymultibulk
);
addReply
Null(c
);
geoArrayFree(ga);
geoArrayFree(ga);
return;
return;
}
}
...
@@ -597,11 +597,11 @@ void georadiusGeneric(client *c, int flags) {
...
@@ -597,11 +597,11 @@ void georadiusGeneric(client *c, int flags) {
if (withhash)
if (withhash)
option_length++;
option_length++;
/* The
multibulk
len we send is exactly result_length. The result is
/* The
array
len we send is exactly result_length. The result is
* either all strings of just zset members *or* a nested multi-bulk
* either all strings of just zset members *or* a nested multi-bulk
* reply containing the zset member string _and_ all the additional
* reply containing the zset member string _and_ all the additional
* options the user enabled for this request. */
* options the user enabled for this request. */
addReply
MultiBulk
Len
(
c
,
returned_items
);
addReply
Array
Len(c, returned_items);
/* Finally send results back to the caller */
/* Finally send results back to the caller */
int i;
int i;
...
@@ -613,7 +613,7 @@ void georadiusGeneric(client *c, int flags) {
...
@@ -613,7 +613,7 @@ void georadiusGeneric(client *c, int flags) {
* as a nested multi-bulk. Add 1 to account for result value
* as a nested multi-bulk. Add 1 to account for result value
* itself. */
* itself. */
if (option_length)
if (option_length)
addReply
MultiBulk
Len
(
c
,
option_length
+
1
);
addReply
Array
Len(c, option_length + 1);
addReplyBulkSds(c,gp->member);
addReplyBulkSds(c,gp->member);
gp->member = NULL;
gp->member = NULL;
...
@@ -625,7 +625,7 @@ void georadiusGeneric(client *c, int flags) {
...
@@ -625,7 +625,7 @@ void georadiusGeneric(client *c, int flags) {
addReplyLongLong(c, gp->score);
addReplyLongLong(c, gp->score);
if (withcoords) {
if (withcoords) {
addReply
MultiBulk
Len
(
c
,
2
);
addReply
Array
Len(c, 2);
addReplyHumanLongDouble(c, gp->longitude);
addReplyHumanLongDouble(c, gp->longitude);
addReplyHumanLongDouble(c, gp->latitude);
addReplyHumanLongDouble(c, gp->latitude);
}
}
...
@@ -706,11 +706,11 @@ void geohashCommand(client *c) {
...
@@ -706,11 +706,11 @@ void geohashCommand(client *c) {
/* Geohash elements one after the other, using a null bulk reply for
/* Geohash elements one after the other, using a null bulk reply for
* missing elements. */
* missing elements. */
addReply
MultiBulk
Len
(
c
,
c
->
argc
-
2
);
addReply
Array
Len(c,c->argc-2);
for (j = 2; j < c->argc; j++) {
for (j = 2; j < c->argc; j++) {
double score;
double score;
if (!zobj || zsetScore(zobj, c->argv[j]->ptr, &score) == C_ERR) {
if (!zobj || zsetScore(zobj, c->argv[j]->ptr, &score) == C_ERR) {
addReply
(
c
,
shared
.
nullbulk
);
addReply
Null(c
);
} else {
} else {
/* The internal format we use for geocoding is a bit different
/* The internal format we use for geocoding is a bit different
* than the standard, since we use as initial latitude range
* than the standard, since we use as initial latitude range
...
@@ -721,7 +721,7 @@ void geohashCommand(client *c) {
...
@@ -721,7 +721,7 @@ void geohashCommand(client *c) {
/* Decode... */
/* Decode... */
double xy[2];
double xy[2];
if (!decodeGeohash(score,xy)) {
if (!decodeGeohash(score,xy)) {
addReply
(
c
,
shared
.
nullbulk
);
addReply
Null(c
);
continue;
continue;
}
}
...
@@ -759,19 +759,19 @@ void geoposCommand(client *c) {
...
@@ -759,19 +759,19 @@ void geoposCommand(client *c) {
/* Report elements one after the other, using a null bulk reply for
/* Report elements one after the other, using a null bulk reply for
* missing elements. */
* missing elements. */
addReply
MultiBulk
Len
(
c
,
c
->
argc
-
2
);
addReply
Array
Len(c,c->argc-2);
for (j = 2; j < c->argc; j++) {
for (j = 2; j < c->argc; j++) {
double score;
double score;
if (!zobj || zsetScore(zobj, c->argv[j]->ptr, &score) == C_ERR) {
if (!zobj || zsetScore(zobj, c->argv[j]->ptr, &score) == C_ERR) {
addReply
(
c
,
shared
.
nullmultibulk
);
addReply
Null(c
);
} else {
} else {
/* Decode... */
/* Decode... */
double xy[2];
double xy[2];
if (!decodeGeohash(score,xy)) {
if (!decodeGeohash(score,xy)) {
addReply
(
c
,
shared
.
nullmultibulk
);
addReply
Null(c
);
continue;
continue;
}
}
addReply
MultiBulk
Len
(
c
,
2
);
addReply
Array
Len(c,2);
addReplyHumanLongDouble(c,xy[0]);
addReplyHumanLongDouble(c,xy[0]);
addReplyHumanLongDouble(c,xy[1]);
addReplyHumanLongDouble(c,xy[1]);
}
}
...
@@ -797,7 +797,7 @@ void geodistCommand(client *c) {
...
@@ -797,7 +797,7 @@ void geodistCommand(client *c) {
/* Look up the requested zset */
/* Look up the requested zset */
robj *zobj = NULL;
robj *zobj = NULL;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
null
bulk
))
if ((zobj = lookupKeyReadOrReply(c, c->argv[1], shared.null
[c->resp]
))
== NULL || checkType(c, zobj, OBJ_ZSET)) return;
== NULL || checkType(c, zobj, OBJ_ZSET)) return;
/* Get the scores. We need both otherwise NULL is returned. */
/* Get the scores. We need both otherwise NULL is returned. */
...
@@ -805,13 +805,13 @@ void geodistCommand(client *c) {
...
@@ -805,13 +805,13 @@ void geodistCommand(client *c) {
if (zsetScore(zobj, c->argv[2]->ptr, &score1) == C_ERR ||
if (zsetScore(zobj, c->argv[2]->ptr, &score1) == C_ERR ||
zsetScore(zobj, c->argv[3]->ptr, &score2) == C_ERR)
zsetScore(zobj, c->argv[3]->ptr, &score2) == C_ERR)
{
{
addReply
(
c
,
shared
.
nullbulk
);
addReply
Null(c
);
return;
return;
}
}
/* Decode & compute the distance. */
/* Decode & compute the distance. */
if (!decodeGeohash(score1,xyxy) || !decodeGeohash(score2,xyxy+2))
if (!decodeGeohash(score1,xyxy) || !decodeGeohash(score2,xyxy+2))
addReply
(
c
,
shared
.
nullbulk
);
addReply
Null(c
);
else
else
addReplyDoubleDistance(c,
addReplyDoubleDistance(c,
geohashGetDistance(xyxy[0],xyxy[1],xyxy[2],xyxy[3]) / to_meter);
geohashGetDistance(xyxy[0],xyxy[1],xyxy[2],xyxy[3]) / to_meter);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment