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
a9f8a8cb
Commit
a9f8a8cb
authored
Apr 01, 2020
by
antirez
Browse files
LCS: implement KEYS option.
parent
4aa24e62
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_string.c
View file @
a9f8a8cb
...
@@ -482,12 +482,13 @@ void strlenCommand(client *c) {
...
@@ -482,12 +482,13 @@ void strlenCommand(client *c) {
/* LCS -- Longest common subsequence.
/* LCS -- Longest common subsequence.
*
*
* LCS [IDX] [STOREIDX <key>] STRINGS <string> <string> */
* LCS [IDX] [STOREIDX <key>] STRINGS <string> <string>
| KEYS <keya> <keyb>
*/
void
lcsCommand
(
client
*
c
)
{
void
lcsCommand
(
client
*
c
)
{
uint32_t
i
,
j
;
uint32_t
i
,
j
;
sds
a
=
NULL
,
b
=
NULL
;
sds
a
=
NULL
,
b
=
NULL
;
int
getlen
=
0
,
getidx
=
0
;
int
getlen
=
0
,
getidx
=
0
;
robj
*
idxkey
=
NULL
;
/* STOREIDX will set this and getidx to 1. */
robj
*
idxkey
=
NULL
;
/* STOREIDX will set this and getidx to 1. */
robj
*
obja
=
NULL
,
*
objb
=
NULL
;
for
(
j
=
1
;
j
<
(
uint32_t
)
c
->
argc
;
j
++
)
{
for
(
j
=
1
;
j
<
(
uint32_t
)
c
->
argc
;
j
++
)
{
char
*
opt
=
c
->
argv
[
j
]
->
ptr
;
char
*
opt
=
c
->
argv
[
j
]
->
ptr
;
...
@@ -509,6 +510,18 @@ void lcsCommand(client *c) {
...
@@ -509,6 +510,18 @@ void lcsCommand(client *c) {
a
=
c
->
argv
[
j
+
1
]
->
ptr
;
a
=
c
->
argv
[
j
+
1
]
->
ptr
;
b
=
c
->
argv
[
j
+
2
]
->
ptr
;
b
=
c
->
argv
[
j
+
2
]
->
ptr
;
j
+=
2
;
j
+=
2
;
}
else
if
(
!
strcasecmp
(
opt
,
"KEYS"
))
{
if
(
moreargs
!=
2
)
{
addReplyError
(
c
,
"LCS requires exactly two keys"
);
return
;
}
obja
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
j
+
1
]);
objb
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
j
+
2
]);
obja
=
obja
?
getDecodedObject
(
obja
)
:
createStringObject
(
""
,
0
);
objb
=
objb
?
getDecodedObject
(
objb
)
:
createStringObject
(
""
,
0
);
a
=
obja
->
ptr
;
b
=
objb
->
ptr
;
j
+=
2
;
}
else
{
}
else
{
addReply
(
c
,
shared
.
syntaxerr
);
addReply
(
c
,
shared
.
syntaxerr
);
return
;
return
;
...
@@ -517,7 +530,8 @@ void lcsCommand(client *c) {
...
@@ -517,7 +530,8 @@ void lcsCommand(client *c) {
/* Complain if the user passed ambiguous parameters. */
/* Complain if the user passed ambiguous parameters. */
if
(
a
==
NULL
)
{
if
(
a
==
NULL
)
{
addReplyError
(
c
,
"STRINGS <string-a> <string-b> is mandatory"
);
addReplyError
(
c
,
"Please specify two strings: "
"STRINGS or KEYS options are mandatory"
);
return
;
return
;
}
else
if
(
getlen
&&
(
getidx
&&
idxkey
==
NULL
))
{
}
else
if
(
getlen
&&
(
getidx
&&
idxkey
==
NULL
))
{
addReplyError
(
c
,
addReplyError
(
c
,
...
@@ -651,6 +665,8 @@ void lcsCommand(client *c) {
...
@@ -651,6 +665,8 @@ void lcsCommand(client *c) {
}
}
/* Cleanup. */
/* Cleanup. */
if
(
obja
)
decrRefCount
(
obja
);
if
(
objb
)
decrRefCount
(
objb
);
sdsfree
(
result
);
sdsfree
(
result
);
zfree
(
lcs
);
zfree
(
lcs
);
return
;
return
;
...
...
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