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
47404240
Commit
47404240
authored
Apr 07, 2017
by
Qu Chen
Committed by
antirez
Jun 14, 2017
Browse files
Implement getKeys procedure for georadius and georadiusbymember
commands.
parent
5877c02c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
47404240
...
...
@@ -1312,6 +1312,44 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey
return
keys
;
}
/* Helper function to extract keys from following commands:
* GEORADIUS key x y radius unit [WITHDIST] [WITHHASH] [WITHCOORD] [ASC|DESC]
* [COUNT count] [STORE key] [STOREDIST key]
* GEORADIUSBYMEMBER key member radius unit ... options ... */
int
*
georadiusGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
num
,
*
keys
;
UNUSED
(
cmd
);
/* Check for the presence of the stored key in the command */
int
stored_key
=
-
1
;
for
(
i
=
5
;
i
<
argc
;
i
++
)
{
char
*
arg
=
argv
[
i
]
->
ptr
;
/* For the case when user specifies both "store" and "storedist" options, the
* second key specified would override the first key. This behavior is kept
* the same as in georadiusCommand method.
*/
if
((
!
strcasecmp
(
arg
,
"store"
)
||
!
strcasecmp
(
arg
,
"storedist"
))
&&
((
i
+
1
)
<
argc
))
{
stored_key
=
i
+
1
;
i
++
;
}
}
num
=
1
+
(
stored_key
==
-
1
?
0
:
1
);
/* Keys in the command come from two places:
* argv[1] = key,
* argv[5...n] = stored key if present
*/
keys
=
zmalloc
(
sizeof
(
int
)
*
num
);
/* Add all key positions to keys[] */
keys
[
0
]
=
1
;
if
(
num
>
1
)
{
keys
[
1
]
=
stored_key
;
}
*
numkeys
=
num
;
return
keys
;
}
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
* a fast way a key that belongs to a specified hash slot. This is useful
* while rehashing the cluster and in other conditions when we need to
...
...
src/server.c
View file @
47404240
...
...
@@ -290,8 +290,8 @@ struct redisCommand redisCommandTable[] = {
{
"wait"
,
waitCommand
,
3
,
"s"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"command"
,
commandCommand
,
0
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geoadd"
,
geoaddCommand
,
-
5
,
"wm"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadius"
,
georadiusCommand
,
-
6
,
"w"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadiusbymember"
,
georadiusByMemberCommand
,
-
5
,
"w"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadius"
,
georadiusCommand
,
-
6
,
"w"
,
0
,
georadiusGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"georadiusbymember"
,
georadiusByMemberCommand
,
-
5
,
"w"
,
0
,
georadiusGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"geohash"
,
geohashCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geopos"
,
geoposCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geodist"
,
geodistCommand
,
-
4
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
...
...
src/server.h
View file @
47404240
...
...
@@ -1730,6 +1730,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *num
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
sortGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
migrateGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
georadiusGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
/* Cluster */
void
clusterInit
(
void
);
...
...
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