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
04cf02e8
You need to sign in or sign up before continuing.
Commit
04cf02e8
authored
Mar 10, 2014
by
antirez
Browse files
Cluster: SORT get keys helper implemented.
parent
21765c85
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
04cf02e8
...
@@ -1028,6 +1028,51 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
...
@@ -1028,6 +1028,51 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
return
keys
;
return
keys
;
}
}
/* Helper function to extract keys from the SORT command.
*
* SORT <sort-key> ... STORE <store-key> ...
*
* The first argument of SORT is always a key, however a list of options
* follow in SQL-alike style. Here we parse just the minimum in order to
* correctly identify keys in the "STORE" option. */
int
*
sortGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
j
,
num
,
*
keys
;
REDIS_NOTUSED
(
cmd
);
num
=
0
;
keys
=
zmalloc
(
sizeof
(
int
)
*
2
);
/* Alloc 2 places for the worst case. */
keys
[
num
++
]
=
1
;
/* <sort-key> is always present. */
/* Search for STORE option. By default we consider options to don't
* have arguments, so if we find an unknown option name we scan the
* next. However there are options with 1 or 2 arguments, so we
* provide a list here in order to skip the right number of args. */
struct
{
char
*
name
;
int
skip
;
}
skiplist
[]
=
{
{
"limit"
,
2
},
{
"get"
,
1
},
{
"by"
,
1
},
{
NULL
,
0
}
/* End of elements. */
};
for
(
i
=
2
;
i
<
argc
;
i
++
)
{
for
(
j
=
0
;
skiplist
[
j
].
name
!=
NULL
;
j
++
)
{
if
(
!
strcasecmp
(
argv
[
i
]
->
ptr
,
skiplist
[
j
].
name
))
{
i
+=
skiplist
[
j
].
skip
;
break
;
}
else
if
(
!
strcasecmp
(
argv
[
i
]
->
ptr
,
"store"
)
&&
i
+
1
<
argc
)
{
keys
[
num
++
]
=
i
+
1
;
/* <store-key> */
break
;
}
}
}
*
numkeys
=
num
;
return
keys
;
}
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
/* 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
* a fast way a key that belongs to a specified hash slot. This is useful
* while rehashing the cluster. */
* while rehashing the cluster. */
...
...
src/redis.c
View file @
04cf02e8
...
@@ -232,7 +232,7 @@ struct redisCommand redisCommandTable[] = {
...
@@ -232,7 +232,7 @@ struct redisCommand redisCommandTable[] = {
{
"replconf"
,
replconfCommand
,
-
1
,
"arslt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"replconf"
,
replconfCommand
,
-
1
,
"arslt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushall"
,
flushallCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushall"
,
flushallCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"sort"
,
sortCommand
,
-
2
,
"wm"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"sort"
,
sortCommand
,
-
2
,
"wm"
,
0
,
sortGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"info"
,
infoCommand
,
-
1
,
"rlt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"info"
,
infoCommand
,
-
1
,
"rlt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"monitor"
,
monitorCommand
,
1
,
"ars"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"monitor"
,
monitorCommand
,
1
,
"ars"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"ttl"
,
ttlCommand
,
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"ttl"
,
ttlCommand
,
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
...
...
src/redis.h
View file @
04cf02e8
...
@@ -1241,6 +1241,7 @@ int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *nu
...
@@ -1241,6 +1241,7 @@ int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *nu
void
getKeysFreeResult
(
int
*
result
);
void
getKeysFreeResult
(
int
*
result
);
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
sortGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
/* Cluster */
/* Cluster */
void
clusterInit
(
void
);
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