|
| 1 | +From bacb04f89fe22b98881f86523ce8f7b8b6542084 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Fri, 7 Apr 2017 22:31:11 +0000 |
| 4 | +Subject: [PATCH 03/19] Implement getKeys procedure for georadius and |
| 5 | + georadiusbymember commands. |
| 6 | + |
| 7 | +--- |
| 8 | + src/db.c | 38 ++++++++++++++++++++++++++++++++++++++ |
| 9 | + src/server.c | 4 ++-- |
| 10 | + src/server.h | 1 + |
| 11 | + 3 files changed, 41 insertions(+), 2 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/db.c b/src/db.c |
| 14 | +index fba731c9..75905e2d 100644 |
| 15 | +--- a/src/db.c |
| 16 | ++++ b/src/db.c |
| 17 | +@@ -1234,6 +1234,44 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey |
| 18 | + return keys; |
| 19 | + } |
| 20 | + |
| 21 | ++/* Helper function to extract keys from following commands: |
| 22 | ++ * GEORADIUS key x y radius unit [WITHDIST] [WITHHASH] [WITHCOORD] [ASC|DESC] |
| 23 | ++ * [COUNT count] [STORE key] [STOREDIST key] |
| 24 | ++ * GEORADIUSBYMEMBER key member radius unit ... options ... */ |
| 25 | ++int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) { |
| 26 | ++ int i, num, *keys; |
| 27 | ++ UNUSED(cmd); |
| 28 | ++ |
| 29 | ++ /* Check for the presence of the stored key in the command */ |
| 30 | ++ int stored_key = -1; |
| 31 | ++ for (i = 5; i < argc; i++) { |
| 32 | ++ char *arg = argv[i]->ptr; |
| 33 | ++ /* For the case when user specifies both "store" and "storedist" options, the |
| 34 | ++ * second key specified would override the first key. This behavior is kept |
| 35 | ++ * the same as in georadiusCommand method. |
| 36 | ++ */ |
| 37 | ++ if ((!strcasecmp(arg, "store") || !strcasecmp(arg, "storedist")) && ((i+1) < argc)) { |
| 38 | ++ stored_key = i+1; |
| 39 | ++ i++; |
| 40 | ++ } |
| 41 | ++ } |
| 42 | ++ num = 1 + (stored_key == -1 ? 0 : 1); |
| 43 | ++ |
| 44 | ++ /* Keys in the command come from two places: |
| 45 | ++ * argv[1] = key, |
| 46 | ++ * argv[5...n] = stored key if present |
| 47 | ++ */ |
| 48 | ++ keys = zmalloc(sizeof(int) * num); |
| 49 | ++ |
| 50 | ++ /* Add all key positions to keys[] */ |
| 51 | ++ keys[0] = 1; |
| 52 | ++ if(num > 1) { |
| 53 | ++ keys[1] = stored_key; |
| 54 | ++ } |
| 55 | ++ *numkeys = num; |
| 56 | ++ return keys; |
| 57 | ++} |
| 58 | ++ |
| 59 | + /* Slot to Key API. This is used by Redis Cluster in order to obtain in |
| 60 | + * a fast way a key that belongs to a specified hash slot. This is useful |
| 61 | + * while rehashing the cluster. */ |
| 62 | +diff --git a/src/server.c b/src/server.c |
| 63 | +index 71bcda7d..cc23c817 100644 |
| 64 | +--- a/src/server.c |
| 65 | ++++ b/src/server.c |
| 66 | +@@ -284,8 +284,8 @@ struct redisCommand redisCommandTable[] = { |
| 67 | + {"wait",waitCommand,3,"s",0,NULL,0,0,0,0,0}, |
| 68 | + {"command",commandCommand,0,"lt",0,NULL,0,0,0,0,0}, |
| 69 | + {"geoadd",geoaddCommand,-5,"wm",0,NULL,1,1,1,0,0}, |
| 70 | +- {"georadius",georadiusCommand,-6,"w",0,NULL,1,1,1,0,0}, |
| 71 | +- {"georadiusbymember",georadiusByMemberCommand,-5,"w",0,NULL,1,1,1,0,0}, |
| 72 | ++ {"georadius",georadiusCommand,-6,"w",0,georadiusGetKeys,1,1,1,0,0}, |
| 73 | ++ {"georadiusbymember",georadiusByMemberCommand,-5,"w",0,georadiusGetKeys,1,1,1,0,0}, |
| 74 | + {"geohash",geohashCommand,-2,"r",0,NULL,1,1,1,0,0}, |
| 75 | + {"geopos",geoposCommand,-2,"r",0,NULL,1,1,1,0,0}, |
| 76 | + {"geodist",geodistCommand,-4,"r",0,NULL,1,1,1,0,0}, |
| 77 | +diff --git a/src/server.h b/src/server.h |
| 78 | +index 3fa7c3ac..4ca73a25 100644 |
| 79 | +--- a/src/server.h |
| 80 | ++++ b/src/server.h |
| 81 | +@@ -1435,6 +1435,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *num |
| 82 | + int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); |
| 83 | + int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); |
| 84 | + int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); |
| 85 | ++int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); |
| 86 | + |
| 87 | + /* Cluster */ |
| 88 | + void clusterInit(void); |
| 89 | +-- |
| 90 | +2.13.1 |
| 91 | + |
0 commit comments