Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
0d543fe8
Commit
0d543fe8
authored
Jun 03, 2020
by
liuminghang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename commands to args
parent
a8f27723
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
23 deletions
+23
-23
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+12
-12
redis_command.cpp
src/brpc/redis_command.cpp
+7
-7
redis_command.h
src/brpc/redis_command.h
+4
-4
No files found.
src/brpc/policy/redis_protocol.cpp
View file @
0d543fe8
...
...
@@ -76,13 +76,13 @@ public:
};
int
ConsumeCommand
(
RedisConnContext
*
ctx
,
const
std
::
vector
<
butil
::
StringPiece
>&
command
s
,
const
std
::
vector
<
butil
::
StringPiece
>&
arg
s
,
bool
flush_batched
,
butil
::
IOBufAppender
*
appender
)
{
RedisReply
output
(
&
ctx
->
arena
);
RedisCommandHandlerResult
result
=
REDIS_CMD_HANDLED
;
if
(
ctx
->
transaction_handler
)
{
result
=
ctx
->
transaction_handler
->
Run
(
command
s
,
&
output
,
flush_batched
);
result
=
ctx
->
transaction_handler
->
Run
(
arg
s
,
&
output
,
flush_batched
);
if
(
result
==
REDIS_CMD_HANDLED
)
{
ctx
->
transaction_handler
.
reset
(
NULL
);
}
else
if
(
result
==
REDIS_CMD_BATCHED
)
{
...
...
@@ -90,13 +90,13 @@ int ConsumeCommand(RedisConnContext* ctx,
return
-
1
;
}
}
else
{
RedisCommandHandler
*
ch
=
ctx
->
redis_service
->
FindCommandHandler
(
command
s
[
0
]);
RedisCommandHandler
*
ch
=
ctx
->
redis_service
->
FindCommandHandler
(
arg
s
[
0
]);
if
(
!
ch
)
{
char
buf
[
64
];
snprintf
(
buf
,
sizeof
(
buf
),
"ERR unknown command `%s`"
,
command
s
[
0
].
as_string
().
c_str
());
snprintf
(
buf
,
sizeof
(
buf
),
"ERR unknown command `%s`"
,
arg
s
[
0
].
as_string
().
c_str
());
output
.
SetError
(
buf
);
}
else
{
result
=
ch
->
Run
(
command
s
,
&
output
,
flush_batched
);
result
=
ch
->
Run
(
arg
s
,
&
output
,
flush_batched
);
if
(
result
==
REDIS_CMD_CONTINUE
)
{
if
(
ctx
->
batched_size
!=
0
)
{
LOG
(
ERROR
)
<<
"CONTINUE should not be returned in a batched process."
;
...
...
@@ -159,26 +159,26 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
ctx
=
new
RedisConnContext
(
rs
);
socket
->
reset_parsing_context
(
ctx
);
}
std
::
vector
<
butil
::
StringPiece
>
current_
command
s
;
std
::
vector
<
butil
::
StringPiece
>
current_
arg
s
;
butil
::
IOBufAppender
appender
;
ParseError
err
=
PARSE_OK
;
err
=
ctx
->
parser
.
Consume
(
*
source
,
&
current_
command
s
,
&
ctx
->
arena
);
err
=
ctx
->
parser
.
Consume
(
*
source
,
&
current_
arg
s
,
&
ctx
->
arena
);
if
(
err
!=
PARSE_OK
)
{
return
MakeParseError
(
err
);
}
while
(
true
)
{
std
::
vector
<
butil
::
StringPiece
>
next_
command
s
;
err
=
ctx
->
parser
.
Consume
(
*
source
,
&
next_
command
s
,
&
ctx
->
arena
);
std
::
vector
<
butil
::
StringPiece
>
next_
arg
s
;
err
=
ctx
->
parser
.
Consume
(
*
source
,
&
next_
arg
s
,
&
ctx
->
arena
);
if
(
err
!=
PARSE_OK
)
{
break
;
}
if
(
ConsumeCommand
(
ctx
,
current_
command
s
,
false
,
&
appender
)
!=
0
)
{
if
(
ConsumeCommand
(
ctx
,
current_
arg
s
,
false
,
&
appender
)
!=
0
)
{
return
MakeParseError
(
PARSE_ERROR_ABSOLUTELY_WRONG
);
}
current_
commands
.
swap
(
next_command
s
);
current_
args
.
swap
(
next_arg
s
);
}
if
(
ConsumeCommand
(
ctx
,
current_
command
s
,
if
(
ConsumeCommand
(
ctx
,
current_
arg
s
,
true
/*must be the last message*/
,
&
appender
)
!=
0
)
{
return
MakeParseError
(
PARSE_ERROR_ABSOLUTELY_WRONG
);
}
...
...
src/brpc/redis_command.cpp
View file @
0d543fe8
...
...
@@ -362,7 +362,7 @@ RedisCommandParser::RedisCommandParser()
,
_index
(
0
)
{}
ParseError
RedisCommandParser
::
Consume
(
butil
::
IOBuf
&
buf
,
std
::
vector
<
butil
::
StringPiece
>*
command
s
,
std
::
vector
<
butil
::
StringPiece
>*
arg
s
,
butil
::
Arena
*
arena
)
{
const
char
*
pfc
=
(
const
char
*
)
buf
.
fetch1
();
if
(
pfc
==
NULL
)
{
...
...
@@ -398,8 +398,8 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
_parsing_array
=
true
;
_length
=
value
;
_index
=
0
;
_
command
s
.
resize
(
value
);
return
Consume
(
buf
,
command
s
,
arena
);
_
arg
s
.
resize
(
value
);
return
Consume
(
buf
,
arg
s
,
arena
);
}
CHECK
(
_index
<
_length
)
<<
"a complete command has been parsed. "
"impl of RedisCommandParser::Parse is buggy"
;
...
...
@@ -420,7 +420,7 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
char
*
d
=
(
char
*
)
arena
->
allocate
((
len
/
8
+
1
)
*
8
);
buf
.
cutn
(
d
,
len
);
d
[
len
]
=
'\0'
;
_
command
s
[
_index
]
=
butil
::
StringPiece
(
d
,
len
);
_
arg
s
[
_index
]
=
butil
::
StringPiece
(
d
,
len
);
if
(
_index
==
0
)
{
// convert it to lowercase when it is command name
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -434,9 +434,9 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
return
PARSE_ERROR_ABSOLUTELY_WRONG
;
}
if
(
++
_index
<
_length
)
{
return
Consume
(
buf
,
command
s
,
arena
);
return
Consume
(
buf
,
arg
s
,
arena
);
}
commands
->
swap
(
_command
s
);
args
->
swap
(
_arg
s
);
Reset
();
return
PARSE_OK
;
}
...
...
@@ -445,7 +445,7 @@ void RedisCommandParser::Reset() {
_parsing_array
=
false
;
_length
=
0
;
_index
=
0
;
_
command
s
.
clear
();
_
arg
s
.
clear
();
}
}
// namespace brpc
src/brpc/redis_command.h
View file @
0d543fe8
...
...
@@ -48,9 +48,9 @@ public:
RedisCommandParser
();
// Parse raw message from `buf'. Return PARSE_OK and set the parsed command
// to `
commands' and length to `len' if successful. Memory of commands are
//
allocated
in `arena'.
ParseError
Consume
(
butil
::
IOBuf
&
buf
,
std
::
vector
<
butil
::
StringPiece
>*
command
s
,
// to `
args' and length to `len' if successful. Memory of args are allocated
// in `arena'.
ParseError
Consume
(
butil
::
IOBuf
&
buf
,
std
::
vector
<
butil
::
StringPiece
>*
arg
s
,
butil
::
Arena
*
arena
);
private
:
...
...
@@ -60,7 +60,7 @@ private:
bool
_parsing_array
;
// if the parser has met array indicator '*'
int
_length
;
// array length
int
_index
;
// current parsing array index
std
::
vector
<
butil
::
StringPiece
>
_
command
s
;
// parsed command string
std
::
vector
<
butil
::
StringPiece
>
_
arg
s
;
// parsed command string
};
}
// namespace brpc
...
...
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