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
b7ce583a
Commit
b7ce583a
authored
Sep 17, 2020
by
bodong.ybd
Committed by
Oran Agra
Sep 24, 2020
Browse files
Refactor multi-key command get keys proc
parent
e08bf166
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
b7ce583a
...
@@ -1386,86 +1386,54 @@ void getKeysFreeResult(int *result) {
...
@@ -1386,86 +1386,54 @@ void getKeysFreeResult(int *result) {
}
}
/* Helper function to extract keys from following commands:
/* Helper function to extract keys from following commands:
* COMMAND [destkey] <num-keys> <key> [...] <key> [...] ... <options>
*
* eg:
* ZUNION <num-keys> <key> <key> ... <key> <options>
* ZUNIONSTORE <destkey> <num-keys> <key> <key> ... <key> <options>
* ZUNIONSTORE <destkey> <num-keys> <key> <key> ... <key> <options>
* ZINTERSTORE <destkey> <num-keys> <key> <key> ... <key> <options> */
*
int
*
zunionInterStoreGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
* 'storeKeyOfs': destkey index, 0 means destkey not exists.
* 'keyCountOfs': num-keys index.
* 'firstKeyOfs': firstkey index.
* 'keyStep': the interval of each key, usually this value is 1.
* */
int
*
genericGetKeys
(
int
storeKeyOfs
,
int
keyCountOfs
,
int
firstKeyOfs
,
int
keyStep
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
num
,
*
keys
;
int
i
,
num
,
*
keys
;
UNUSED
(
cmd
);
num
=
atoi
(
argv
[
2
]
->
ptr
);
num
=
atoi
(
argv
[
keyCountOfs
]
->
ptr
);
/* Sanity check. Don't return any key if the command is going to
/* Sanity check. Don't return any key if the command is going to
* reply with syntax error. */
* reply with syntax error.
(no input keys).
*/
if
(
num
<
1
||
num
>
(
argc
-
3
)
)
{
if
(
num
<
1
||
num
>
(
argc
-
firstKeyOfs
)
/
keyStep
)
{
*
numkeys
=
0
;
*
numkeys
=
0
;
return
NULL
;
return
NULL
;
}
}
/* Keys in z{union,inter}store come from two places:
* argv[1] = storage key,
* argv[3...n] = keys to intersect */
keys
=
getKeysTempBuffer
;
keys
=
getKeysTempBuffer
;
if
(
num
+
1
>
MAX_KEYS_BUFFER
)
*
numkeys
=
storeKeyOfs
?
num
+
1
:
num
;
keys
=
zmalloc
(
sizeof
(
int
)
*
(
num
+
1
));
if
(
*
numkeys
>
MAX_KEYS_BUFFER
)
keys
=
zmalloc
(
sizeof
(
int
)
*
(
*
numkeys
));
/* Add all key positions for argv[
3
...n] to keys[] */
/* Add all key positions for argv[
firstKeyOfs
...n] to keys[] */
for
(
i
=
0
;
i
<
num
;
i
++
)
keys
[
i
]
=
3
+
i
;
for
(
i
=
0
;
i
<
num
;
i
++
)
keys
[
i
]
=
firstKeyOfs
+
(
i
*
keyStep
)
;
/* Finally add the argv[1] key position (the storage key target). */
if
(
storeKeyOfs
)
keys
[
num
]
=
storeKeyOfs
;
keys
[
num
]
=
1
;
*
numkeys
=
num
+
1
;
/* Total keys = {union,inter} keys + storage key */
return
keys
;
return
keys
;
}
}
/* Helper function to extract keys from following commands:
int
*
zunionInterStoreGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
* ZUNION <num-keys> <key> <key> ... <key> <options>
* ZINTER <num-keys> <key> <key> ... <key> <options> */
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
num
,
*
keys
;
UNUSED
(
cmd
);
UNUSED
(
cmd
);
return
genericGetKeys
(
1
,
2
,
3
,
1
,
argv
,
argc
,
numkeys
);
}
num
=
atoi
(
argv
[
1
]
->
ptr
);
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
/* Sanity check. Don't return any key if the command is going to
UNUSED
(
cmd
);
* reply with syntax error. */
return
genericGetKeys
(
0
,
1
,
2
,
1
,
argv
,
argc
,
numkeys
);
if
(
num
<
1
||
num
>
(
argc
-
2
))
{
*
numkeys
=
0
;
return
NULL
;
}
keys
=
getKeysTempBuffer
;
if
(
num
>
MAX_KEYS_BUFFER
)
keys
=
zmalloc
(
sizeof
(
int
)
*
(
num
));
/* Add all key positions for argv[2...n] to keys[] */
for
(
i
=
0
;
i
<
num
;
i
++
)
keys
[
i
]
=
2
+
i
;
*
numkeys
=
num
;
return
keys
;
}
}
/* Helper function to extract keys from the following commands:
* EVAL <script> <num-keys> <key> <key> ... <key> [more stuff]
* EVALSHA <script> <num-keys> <key> <key> ... <key> [more stuff] */
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
num
,
*
keys
;
UNUSED
(
cmd
);
UNUSED
(
cmd
);
return
genericGetKeys
(
0
,
2
,
3
,
1
,
argv
,
argc
,
numkeys
);
num
=
atoi
(
argv
[
2
]
->
ptr
);
/* Sanity check. Don't return any key if the command is going to
* reply with syntax error. */
if
(
num
<=
0
||
num
>
(
argc
-
3
))
{
*
numkeys
=
0
;
return
NULL
;
}
keys
=
getKeysTempBuffer
;
if
(
num
>
MAX_KEYS_BUFFER
)
keys
=
zmalloc
(
sizeof
(
int
)
*
num
);
*
numkeys
=
num
;
/* Add all key positions for argv[3...n] to keys[] */
for
(
i
=
0
;
i
<
num
;
i
++
)
keys
[
i
]
=
3
+
i
;
return
keys
;
}
}
/* Helper function to extract keys from the SORT command.
/* Helper function to extract keys from the SORT command.
...
...
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