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
458c45ef
Commit
458c45ef
authored
5 years ago
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: change para name of Commandhandler from is_last to flush_back
parent
227f5881
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
18 deletions
+18
-18
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+5
-5
redis.h
src/brpc/redis.h
+3
-3
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+10
-10
No files found.
src/brpc/policy/redis_protocol.cpp
View file @
458c45ef
...
...
@@ -80,12 +80,12 @@ int ConsumeCommand(RedisConnContext* ctx,
const
std
::
vector
<
const
char
*>&
commands
,
const
std
::
string
&
next_command
,
butil
::
Arena
*
arena
,
bool
is_last
,
bool
flush_back
,
butil
::
IOBufAppender
*
appender
)
{
RedisReply
output
(
arena
);
RedisCommandHandler
::
Result
result
=
RedisCommandHandler
::
OK
;
if
(
ctx
->
transaction_handler
)
{
result
=
ctx
->
transaction_handler
->
Run
(
commands
,
&
output
,
is_last
);
result
=
ctx
->
transaction_handler
->
Run
(
commands
,
&
output
,
flush_back
);
if
(
result
==
RedisCommandHandler
::
OK
)
{
ctx
->
transaction_handler
.
reset
(
NULL
);
}
else
if
(
result
==
RedisCommandHandler
::
BATCHED
)
{
...
...
@@ -102,12 +102,12 @@ int ConsumeCommand(RedisConnContext* ctx,
RedisCommandHandler
*
next_ch
=
ctx
->
redis_service
->
FindCommandHandler
(
next_command
);
if
(
next_ch
&&
next_ch
->
TransactionMarker
())
{
is_last
=
true
;
flush_back
=
true
;
}
result
=
ch
->
Run
(
commands
,
&
output
,
is_last
);
result
=
ch
->
Run
(
commands
,
&
output
,
flush_back
);
if
(
result
==
RedisCommandHandler
::
CONTINUE
)
{
if
(
ctx
->
batched_size
!=
0
)
{
LOG
(
ERROR
)
<<
"Do you forget to return OK when
is_last
is true?"
;
LOG
(
ERROR
)
<<
"Do you forget to return OK when
flush_back
is true?"
;
return
-
1
;
}
ctx
->
transaction_handler
.
reset
(
ch
->
NewTransactionHandler
());
...
...
This diff is collapsed.
Click to expand it.
src/brpc/redis.h
View file @
458c45ef
...
...
@@ -248,9 +248,9 @@ public:
// corresponds to args[0]=="set", args[1]=="somekey" and args[2]=="somevalue".
// `output', which should be filled by user, is the content that sent to client side.
// Read brpc/src/redis_reply.h for more usage.
// `
is_last
' indicates whether the commands is the last command of this batch. If user
// `
flush_back
' indicates whether the commands is the last command of this batch. If user
// want to do some batch processing, user should buffer the command and return
// RedisCommandHandler::BATCHED. Once `
is_last
' is true, run all the commands,
// RedisCommandHandler::BATCHED. Once `
flush_back
' is true, run all the commands,
// set `output' to be an array in which every element is the result of batched
// commands and return RedisCommandHandler::OK.
//
...
...
@@ -261,7 +261,7 @@ public:
// it returns RedisCommandHandler::OK. Read the comment below.
virtual
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
=
0
;
bool
flush_back
)
=
0
;
// The Run() returns CONTINUE for "multi", which makes brpc call this method to
// create a transaction_handler to process following commands until transaction_handler
...
...
This diff is collapsed.
Click to expand it.
test/brpc_redis_unittest.cpp
View file @
458c45ef
...
...
@@ -798,8 +798,8 @@ public:
:
_batch_count
(
0
)
{}
brpc
::
RedisCommandHandler
::
Result
OnBatched
(
const
std
::
vector
<
const
char
*>
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
if
(
_batched_command
.
empty
()
&&
is_last
)
{
brpc
::
RedisReply
*
output
,
bool
flush_back
)
{
if
(
_batched_command
.
empty
()
&&
flush_back
)
{
if
(
strcmp
(
args
[
0
],
"set"
)
==
0
)
{
DoSet
(
args
[
1
],
args
[
2
],
output
);
}
else
if
(
strcmp
(
args
[
0
],
"get"
)
==
0
)
{
...
...
@@ -812,7 +812,7 @@ public:
comm
.
push_back
(
args
[
i
]);
}
_batched_command
.
push_back
(
comm
);
if
(
is_last
)
{
if
(
flush_back
)
{
output
->
SetArray
(
_batched_command
.
size
());
for
(
int
i
=
0
;
i
<
(
int
)
_batched_command
.
size
();
++
i
)
{
if
(
_batched_command
[
i
][
0
]
==
"set"
)
{
...
...
@@ -856,13 +856,13 @@ public:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
bool
flush_back
)
{
if
(
args
.
size
()
<
3
)
{
output
->
SetError
(
"ERR wrong number of arguments for 'set' command"
);
return
brpc
::
RedisCommandHandler
::
OK
;
}
if
(
_batch_process
)
{
return
rs
->
OnBatched
(
args
,
output
,
is_last
);
return
rs
->
OnBatched
(
args
,
output
,
flush_back
);
}
else
{
DoSet
(
args
[
1
],
args
[
2
],
output
);
return
brpc
::
RedisCommandHandler
::
OK
;
...
...
@@ -887,13 +887,13 @@ public:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
bool
flush_back
)
{
if
(
args
.
size
()
<
2
)
{
output
->
SetError
(
"ERR wrong number of arguments for 'get' command"
);
return
brpc
::
RedisCommandHandler
::
OK
;
}
if
(
_batch_process
)
{
return
rs
->
OnBatched
(
args
,
output
,
is_last
);
return
rs
->
OnBatched
(
args
,
output
,
flush_back
);
}
else
{
DoGet
(
args
[
1
],
output
);
return
brpc
::
RedisCommandHandler
::
OK
;
...
...
@@ -920,7 +920,7 @@ public:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
bool
flush_back
)
{
if
(
args
.
size
()
<
2
)
{
output
->
SetError
(
"ERR wrong number of arguments for 'incr' command"
);
return
brpc
::
RedisCommandHandler
::
OK
;
...
...
@@ -1034,7 +1034,7 @@ public:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
bool
flush_back
)
{
output
->
SetStatus
(
"OK"
);
return
brpc
::
RedisCommandHandler
::
CONTINUE
;
}
...
...
@@ -1050,7 +1050,7 @@ public:
public
:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
is_last
)
{
bool
flush_back
)
{
if
(
strcmp
(
args
[
0
],
"multi"
)
==
0
)
{
output
->
SetError
(
"ERR duplicate multi"
);
return
brpc
::
RedisCommandHandler
::
CONTINUE
;
...
...
This diff is collapsed.
Click to expand it.
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