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
1b342f75
Commit
1b342f75
authored
Nov 29, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: rename RedisMessage back to RedisReply
parent
64d0bcea
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
20 deletions
+20
-20
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+5
-5
redis.cpp
src/brpc/redis.cpp
+7
-7
redis.h
src/brpc/redis.h
+8
-8
redis_reply.cpp
src/brpc/redis_reply.cpp
+0
-0
redis_reply.h
src/brpc/redis_reply.h
+0
-0
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+0
-0
No files found.
src/brpc/policy/redis_protocol.cpp
View file @
1b342f75
...
...
@@ -58,7 +58,7 @@ struct InputResponse : public InputMessageBase {
}
};
const
char
**
ParseArgs
(
const
Redis
Message
&
message
)
{
const
char
**
ParseArgs
(
const
Redis
Reply
&
message
)
{
const
char
**
args
=
(
const
char
**
)
malloc
(
sizeof
(
const
char
*
)
*
(
message
.
size
()
+
1
/* NULL */
));
for
(
size_t
i
=
0
;
i
<
message
.
size
();
++
i
)
{
...
...
@@ -122,8 +122,8 @@ private:
butil
::
atomic
<
bool
>
_ready
;
public
:
Redis
Message
input_message
;
Redis
Message
output_message
;
Redis
Reply
input_message
;
Redis
Reply
output_message
;
RedisConnContext
*
ctx
;
butil
::
IOBuf
sendbuf
;
butil
::
Arena
arena
;
...
...
@@ -133,7 +133,7 @@ int ConsumeTask(RedisConnContext* ctx, ConsumeTaskDone* done) {
ClosureGuard
done_guard
(
done
);
done
->
ctx
=
ctx
;
ctx
->
Push
(
done
);
Redis
Message
&
output
=
done
->
output_message
;
Redis
Reply
&
output
=
done
->
output_message
;
const
char
**
args
=
ParseArgs
(
done
->
input_message
);
if
(
!
args
)
{
...
...
@@ -339,7 +339,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
if
(
pi
.
with_auth
)
{
if
(
msg
->
response
.
reply_size
()
!=
1
||
!
(
msg
->
response
.
reply
(
0
).
type
()
==
brpc
::
REDIS_
MESSAGE
_STATUS
&&
!
(
msg
->
response
.
reply
(
0
).
type
()
==
brpc
::
REDIS_
REPLY
_STATUS
&&
msg
->
response
.
reply
(
0
).
data
().
compare
(
"OK"
)
==
0
))
{
LOG
(
ERROR
)
<<
"Redis Auth failed: "
<<
msg
->
response
;
return
MakeParseError
(
PARSE_ERROR_NO_RESOURCE
,
...
...
src/brpc/redis.cpp
View file @
1b342f75
...
...
@@ -322,10 +322,10 @@ void RedisResponse::MergeFrom(const RedisResponse& from) {
_nreply
=
new_nreply
;
return
;
}
Redis
Message
*
new_others
=
(
Redis
Message
*
)
_arena
.
allocate
(
sizeof
(
RedisMessage
)
*
(
new_nreply
-
1
));
Redis
Reply
*
new_others
=
(
Redis
Reply
*
)
_arena
.
allocate
(
sizeof
(
RedisReply
)
*
(
new_nreply
-
1
));
for
(
int
i
=
0
;
i
<
new_nreply
-
1
;
++
i
)
{
new
(
new_others
+
i
)
Redis
Message
(
NULL
);
new
(
new_others
+
i
)
Redis
Reply
(
NULL
);
}
int
new_other_index
=
0
;
for
(
int
i
=
1
;
i
<
_nreply
;
++
i
)
{
...
...
@@ -394,14 +394,14 @@ ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count
}
if
(
reply_count
>
1
)
{
if
(
_other_replies
==
NULL
)
{
_other_replies
=
(
Redis
Message
*
)
_arena
.
allocate
(
sizeof
(
Redis
Message
)
*
(
reply_count
-
1
));
_other_replies
=
(
Redis
Reply
*
)
_arena
.
allocate
(
sizeof
(
Redis
Reply
)
*
(
reply_count
-
1
));
if
(
_other_replies
==
NULL
)
{
LOG
(
ERROR
)
<<
"Fail to allocate Redis
Message
["
<<
reply_count
-
1
<<
"]"
;
LOG
(
ERROR
)
<<
"Fail to allocate Redis
Reply
["
<<
reply_count
-
1
<<
"]"
;
return
PARSE_ERROR_ABSOLUTELY_WRONG
;
}
for
(
int
i
=
0
;
i
<
reply_count
-
1
;
++
i
)
{
new
(
&
_other_replies
[
i
])
Redis
Message
(
NULL
);
new
(
&
_other_replies
[
i
])
Redis
Reply
(
NULL
);
}
}
for
(
int
i
=
reply_size
();
i
<
reply_count
;
++
i
)
{
...
...
src/brpc/redis.h
View file @
1b342f75
...
...
@@ -27,7 +27,7 @@
#include "butil/strings/string_piece.h"
#include "butil/arena.h"
#include "brpc/proto_base.pb.h"
#include "brpc/redis_
message
.h"
#include "brpc/redis_
reply
.h"
#include "brpc/parse_result.h"
#include "brpc/callback.h"
#include "brpc/socket.h"
...
...
@@ -161,11 +161,11 @@ public:
int
reply_size
()
const
{
return
_nreply
;
}
// Get index-th reply. If index is out-of-bound, nil reply is returned.
const
Redis
Message
&
reply
(
int
index
)
const
{
const
Redis
Reply
&
reply
(
int
index
)
const
{
if
(
index
<
reply_size
())
{
return
(
index
==
0
?
_first_reply
:
_other_replies
[
index
-
1
]);
}
static
Redis
Message
redis_nil
;
static
Redis
Reply
redis_nil
;
return
redis_nil
;
}
...
...
@@ -203,8 +203,8 @@ private:
void
SharedDtor
();
void
SetCachedSize
(
int
size
)
const
;
Redis
Message
_first_reply
;
Redis
Message
*
_other_replies
;
Redis
Reply
_first_reply
;
Redis
Reply
*
_other_replies
;
butil
::
Arena
_arena
;
int
_nreply
;
mutable
int
_cached_size_
;
...
...
@@ -226,7 +226,7 @@ public:
private
:
typedef
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
RedisCommandHandler
>>
CommandMap
;
friend
ParseResult
ParseRedis
Message
(
butil
::
IOBuf
*
,
Socket
*
,
bool
,
const
void
*
);
friend
ParseResult
ParseRedis
Reply
(
butil
::
IOBuf
*
,
Socket
*
,
bool
,
const
void
*
);
void
CloneCommandMap
(
CommandMap
*
map
);
CommandMap
_command_map
;
};
...
...
@@ -247,7 +247,7 @@ public:
// command "set foo bar" corresponds to args[0] == "set", args[1] == "foo",
// args[2] == "bar" and args[3] == nullptr.
// `output`, which should be filled by user, is the content that sent to client side.
// Read brpc/src/redis_
message
.h for more usage.
// Read brpc/src/redis_
reply
.h for more usage.
// Remember to call `done->Run()` when everything is set up into `output`. The return
// value should be RedisCommandHandler::OK for normal cases. If you want to implement
// transaction, return RedisCommandHandler::CONTINUE until server receives an ending
...
...
@@ -259,7 +259,7 @@ public:
// marker that ends the transaction. User may queue the commands and execute them
// all once an ending marker is received.
virtual
RedisCommandHandler
::
Result
Run
(
const
char
*
args
[],
Redis
Message
*
output
,
Redis
Reply
*
output
,
google
::
protobuf
::
Closure
*
done
)
=
0
;
// Whenever a tcp connection is established, a bunch of new handlers would be created
...
...
src/brpc/redis_
message
.cpp
→
src/brpc/redis_
reply
.cpp
View file @
1b342f75
This diff is collapsed.
Click to expand it.
src/brpc/redis_
message
.h
→
src/brpc/redis_
reply
.h
View file @
1b342f75
This diff is collapsed.
Click to expand it.
test/brpc_redis_unittest.cpp
View file @
1b342f75
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