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
8c5de009
Commit
8c5de009
authored
Jun 08, 2020
by
liuminghang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use string in unordered_map
parent
942f0dd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
+8
-12
redis.cpp
src/brpc/redis.cpp
+6
-8
redis.h
src/brpc/redis.h
+2
-4
No files found.
src/brpc/redis.cpp
View file @
8c5de009
...
...
@@ -436,22 +436,20 @@ std::ostream& operator<<(std::ostream& os, const RedisResponse& response) {
return
os
;
}
bool
RedisService
::
AddCommandHandler
(
const
std
::
string
&
name
,
RedisCommandHandler
*
handler
)
{
butil
::
StringPiece
name_piece
(
name
);
auto
it
=
_command_map
.
find
(
name_piece
);
bool
RedisService
::
AddCommandHandler
(
const
butil
::
StringPiece
&
name
,
RedisCommandHandler
*
handler
)
{
std
::
string
lcname
=
StringToLowerASCII
(
name
.
as_string
());
auto
it
=
_command_map
.
find
(
lcname
);
if
(
it
!=
_command_map
.
end
())
{
LOG
(
ERROR
)
<<
"redis command name="
<<
name
<<
" exist"
;
return
false
;
}
_all_commands
.
push_back
(
name
);
name_piece
=
_all_commands
.
back
();
_command_map
[
name_piece
]
=
handler
;
_command_map
[
lcname
]
=
handler
;
return
true
;
}
RedisCommandHandler
*
RedisService
::
FindCommandHandler
(
const
butil
::
StringPiece
&
name
)
const
{
auto
it
=
_command_map
.
find
(
name
);
auto
it
=
_command_map
.
find
(
name
.
as_string
()
);
if
(
it
!=
_command_map
.
end
())
{
return
it
->
second
;
}
...
...
src/brpc/redis.h
View file @
8c5de009
...
...
@@ -222,16 +222,14 @@ public:
virtual
~
RedisService
()
{}
// Call this function to register `handler` that can handle command `name`.
bool
AddCommandHandler
(
const
std
::
string
&
name
,
RedisCommandHandler
*
handler
);
bool
AddCommandHandler
(
const
butil
::
StringPiece
&
name
,
RedisCommandHandler
*
handler
);
// This function should not be touched by user and used by brpc deverloper only.
RedisCommandHandler
*
FindCommandHandler
(
const
butil
::
StringPiece
&
name
)
const
;
private
:
typedef
BUTIL_HASH_NAMESPACE
::
hash
<
butil
::
StringPiece
>
StringPieceHasher
;
typedef
std
::
unordered_map
<
butil
::
StringPiece
,
RedisCommandHandler
*
,
StringPieceHasher
>
CommandMap
;
typedef
std
::
unordered_map
<
std
::
string
,
RedisCommandHandler
*>
CommandMap
;
CommandMap
_command_map
;
std
::
list
<
std
::
string
>
_all_commands
;
};
enum
RedisCommandHandlerResult
{
...
...
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