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
e804f191
Commit
e804f191
authored
Dec 20, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: change flush_back to flush_batched
parent
22ad6a8d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
23 deletions
+23
-23
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+3
-3
redis.h
src/brpc/redis.h
+3
-3
redis_reply.cpp
src/brpc/redis_reply.cpp
+7
-7
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+10
-10
No files found.
src/brpc/policy/redis_protocol.cpp
View file @
e804f191
...
...
@@ -79,12 +79,12 @@ public:
int
ConsumeCommand
(
RedisConnContext
*
ctx
,
const
std
::
vector
<
const
char
*>&
commands
,
bool
flush_ba
ck
,
bool
flush_ba
tched
,
butil
::
IOBufAppender
*
appender
)
{
RedisReply
output
(
&
ctx
->
arena
);
RedisCommandHandler
::
Result
result
=
RedisCommandHandler
::
OK
;
if
(
ctx
->
transaction_handler
)
{
result
=
ctx
->
transaction_handler
->
Run
(
commands
,
&
output
,
flush_ba
ck
);
result
=
ctx
->
transaction_handler
->
Run
(
commands
,
&
output
,
flush_ba
tched
);
if
(
result
==
RedisCommandHandler
::
OK
)
{
ctx
->
transaction_handler
.
reset
(
NULL
);
}
else
if
(
result
==
RedisCommandHandler
::
BATCHED
)
{
...
...
@@ -98,7 +98,7 @@ int ConsumeCommand(RedisConnContext* ctx,
snprintf
(
buf
,
sizeof
(
buf
),
"ERR unknown command `%s`"
,
commands
[
0
]);
output
.
SetError
(
buf
);
}
else
{
result
=
ch
->
Run
(
commands
,
&
output
,
flush_ba
ck
);
result
=
ch
->
Run
(
commands
,
&
output
,
flush_ba
tched
);
if
(
result
==
RedisCommandHandler
::
CONTINUE
)
{
if
(
ctx
->
batched_size
!=
0
)
{
LOG
(
ERROR
)
<<
"CONTINUE should not be returned in a batched process."
;
...
...
src/brpc/redis.h
View file @
e804f191
...
...
@@ -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.
// `flush_ba
ck' indicates whether the user should flush back
all the results of
// `flush_ba
tched' indicates whether the user should flush
all the results of
// batched commands. If user want to do some batch processing, user should buffer
// the commands and return RedisCommandHandler::BATCHED. Once `flush_ba
ck
' is true,
// the commands and return RedisCommandHandler::BATCHED. Once `flush_ba
tched
' 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
flush_ba
ck
)
=
0
;
bool
flush_ba
tched
)
=
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
...
...
src/brpc/redis_reply.cpp
View file @
e804f191
...
...
@@ -50,30 +50,30 @@ bool RedisReply::SerializeTo(butil::IOBufAppender* appender) {
}
else
{
appender
->
append
(
_data
.
long_str
,
_length
);
}
appender
->
append
(
"
\r\n
"
);
appender
->
append
(
"
\r\n
"
,
2
);
break
;
case
REDIS_REPLY_INTEGER
:
appender
->
push_back
(
':'
);
appender
->
append_decimal
(
_data
.
integer
);
appender
->
append
(
"
\r\n
"
);
appender
->
append
(
"
\r\n
"
,
2
);
break
;
case
REDIS_REPLY_STRING
:
appender
->
push_back
(
'$'
);
appender
->
append_decimal
(
_length
);
appender
->
append
(
"
\r\n
"
);
appender
->
append
(
"
\r\n
"
,
2
);
if
(
_length
!=
npos
)
{
if
(
_length
<
(
int
)
sizeof
(
_data
.
short_str
))
{
appender
->
append
(
_data
.
short_str
,
_length
);
}
else
{
appender
->
append
(
_data
.
long_str
,
_length
);
}
appender
->
append
(
"
\r\n
"
);
appender
->
append
(
"
\r\n
"
,
2
);
}
break
;
case
REDIS_REPLY_ARRAY
:
appender
->
push_back
(
'*'
);
appender
->
append_decimal
(
_length
);
appender
->
append
(
"
\r\n
"
);
appender
->
append
(
"
\r\n
"
,
2
);
if
(
_length
!=
npos
)
{
for
(
int
i
=
0
;
i
<
_length
;
++
i
)
{
if
(
!
_data
.
array
.
replies
[
i
].
SerializeTo
(
appender
))
{
...
...
@@ -83,8 +83,8 @@ bool RedisReply::SerializeTo(butil::IOBufAppender* appender) {
}
break
;
case
REDIS_REPLY_NIL
:
appender
->
append
(
"$-1
\r\n
"
)
;
break
;
LOG
(
ERROR
)
<<
"Do you forget to call SetXXX()?"
;
return
false
;
default
:
CHECK
(
false
)
<<
"unknown redis type="
<<
_type
;
return
false
;
...
...
test/brpc_redis_unittest.cpp
View file @
e804f191
...
...
@@ -798,8 +798,8 @@ public:
:
_batch_count
(
0
)
{}
brpc
::
RedisCommandHandler
::
Result
OnBatched
(
const
std
::
vector
<
const
char
*>
args
,
brpc
::
RedisReply
*
output
,
bool
flush_ba
ck
)
{
if
(
_batched_command
.
empty
()
&&
flush_ba
ck
)
{
brpc
::
RedisReply
*
output
,
bool
flush_ba
tched
)
{
if
(
_batched_command
.
empty
()
&&
flush_ba
tched
)
{
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
(
flush_ba
ck
)
{
if
(
flush_ba
tched
)
{
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
flush_ba
ck
)
{
bool
flush_ba
tched
)
{
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
,
flush_ba
ck
);
return
rs
->
OnBatched
(
args
,
output
,
flush_ba
tched
);
}
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
flush_ba
ck
)
{
bool
flush_ba
tched
)
{
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
,
flush_ba
ck
);
return
rs
->
OnBatched
(
args
,
output
,
flush_ba
tched
);
}
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
flush_ba
ck
)
{
bool
flush_ba
tched
)
{
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
flush_ba
ck
)
{
bool
flush_ba
tched
)
{
output
->
SetStatus
(
"OK"
);
return
brpc
::
RedisCommandHandler
::
CONTINUE
;
}
...
...
@@ -1047,7 +1047,7 @@ public:
public
:
brpc
::
RedisCommandHandler
::
Result
Run
(
const
std
::
vector
<
const
char
*>&
args
,
brpc
::
RedisReply
*
output
,
bool
flush_ba
ck
)
{
bool
flush_ba
tched
)
{
if
(
strcmp
(
args
[
0
],
"multi"
)
==
0
)
{
output
->
SetError
(
"ERR duplicate multi"
);
return
brpc
::
RedisCommandHandler
::
CONTINUE
;
...
...
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