-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rproxy: add incr/incrby/decr/decrby #146
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
40be8ff
use static lib s2
acelyc111 cb631bb
Merge branch 'master' into master
acelyc111 971ce36
Merge branch 'master' into master
acelyc111 74d9bc3
update rdns
acelyc111 883f005
Merge branch 'master' of github.com:acelyc111/pegasus
acelyc111 7523b21
Merge branch 'master' of github.com:acelyc111/pegasus
acelyc111 fd9464f
Merge remote-tracking branch 'origin_xm/master'
acelyc111 beb3103
Merge remote-tracking branch 'origin_xm/master'
acelyc111 65a33cd
Merge remote-tracking branch 'origin_xm/master'
acelyc111 c08ea38
fix pack tools script
acelyc111 a253cd6
Merge branch 'master' into master
acelyc111 f7005eb
Merge remote-tracking branch 'origin_xm/master'
acelyc111 7893bc0
add incr/incrby/decr/decrby for redis proxy
acelyc111 25ba527
add incr/incrby/decr/decrby for redis proxy
acelyc111 a67d264
Merge branch 'master' into inrc_for_rproxy
acelyc111 fbb1b8b
fix compile error on gcc 7.3
acelyc111 a8139c3
Merge branch 'inrc_for_rproxy' of github.com:acelyc111/pegasus into i…
acelyc111 71afe73
add incr/incrby/decr/decrby for redis proxy
acelyc111 65c0218
log optimize
acelyc111 570ea00
optimize log
acelyc111 0b251a7
Merge branch 'master' into inrc_for_rproxy
qinzuoyan 4b87b25
set response as inline for INCR
acelyc111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ std::unordered_map<std::string, redis_parser::redis_call_handler> redis_parser:: | |
{"GEODIST", redis_parser::g_geo_dist}, | ||
{"GEORADIUS", redis_parser::g_geo_radius}, | ||
{"GEORADIUSBYMEMBER", redis_parser::g_geo_radius_by_member}, | ||
{"INCR", redis_parser::g_incr}, | ||
{"INCRBY", redis_parser::g_incr_by}, | ||
{"DECR", redis_parser::g_decr}, | ||
{"DECRBY", redis_parser::g_decr_by}, | ||
}; | ||
|
||
redis_parser::redis_call_handler redis_parser::get_handler(const char *command, unsigned int length) | ||
|
@@ -938,6 +942,108 @@ void redis_parser::geo_radius_by_member(message_entry &entry) | |
hash_key, "", radius_m, count, sort_type, 2000, search_callback); | ||
} | ||
|
||
void redis_parser::incr(message_entry &entry) { counter_internal(entry); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 補充一下注釋?像其他函數一樣。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不用加注释,因为函数名本身就是自解释的。其他有的加了注释是因为跟redis原生命令有些出入 |
||
|
||
void redis_parser::incr_by(message_entry &entry) { counter_internal(entry); } | ||
|
||
void redis_parser::decr(message_entry &entry) { counter_internal(entry); } | ||
|
||
void redis_parser::decr_by(message_entry &entry) { counter_internal(entry); } | ||
|
||
void redis_parser::counter_internal(message_entry &entry) | ||
{ | ||
dassert(!entry.request.buffers.empty(), ""); | ||
dassert(entry.request.buffers[0].length > 0, ""); | ||
const char *command = entry.request.buffers[0].data.data(); | ||
int64_t increment = 1; | ||
if (strcasecmp(command, "INCR") == 0 || strcasecmp(command, "DECR") == 0) { | ||
if (entry.request.buffers.size() != 2) { | ||
dwarn_f("{}: command {} seqid({}) with invalid arguments count: {}", | ||
remote_address.to_string(), | ||
command, | ||
entry.sequence_id, | ||
entry.request.buffers.size()); | ||
redis_simple_string result; | ||
result.is_error = true; | ||
result.message = fmt::format("ERR wrong number of arguments for '{}'", command); | ||
reply_message(entry, result); | ||
return; | ||
} | ||
} else if (strcasecmp(command, "INCRBY") == 0 || strcasecmp(command, "DECRBY") == 0) { | ||
if (entry.request.buffers.size() != 3) { | ||
dwarn_f("{}: command {} seqid({}) with invalid arguments count: {}", | ||
remote_address.to_string(), | ||
command, | ||
entry.sequence_id, | ||
entry.request.buffers.size()); | ||
redis_simple_string result; | ||
result.is_error = true; | ||
result.message = fmt::format("ERR wrong number of arguments for '{}'", command); | ||
reply_message(entry, result); | ||
return; | ||
} | ||
if (!dsn::buf2int64(entry.request.buffers[2].data, increment)) { | ||
dwarn_f("{}: command {} seqid({}) with invalid 'increment': {}", | ||
remote_address.to_string(), | ||
command, | ||
entry.sequence_id, | ||
entry.request.buffers[2].data.to_string()); | ||
redis_simple_string result; | ||
result.is_error = true; | ||
result.message = | ||
fmt::format("ERR wrong type of argument 'increment 'for '{}'", command); | ||
reply_message(entry, result); | ||
return; | ||
} | ||
} else { | ||
dfatal_f("command not support: {}", command); | ||
} | ||
if (strncasecmp(command, "DECR", 4) == 0) { | ||
increment = -increment; | ||
} | ||
|
||
std::shared_ptr<proxy_session> ref_this = shared_from_this(); | ||
auto on_incr_reply = [ref_this, this, command, &entry]( | ||
::dsn::error_code ec, dsn_message_t, dsn_message_t response) { | ||
if (is_session_reset.load(std::memory_order_acquire)) { | ||
dwarn_f("{}: command {} seqid({}) got reply, but session has reset", | ||
remote_address.to_string(), | ||
command, | ||
entry.sequence_id); | ||
return; | ||
} | ||
|
||
if (::dsn::ERR_OK != ec) { | ||
dwarn_f("{}: command {} seqid({}) got reply with error = {}", | ||
remote_address.to_string(), | ||
command, | ||
entry.sequence_id, | ||
ec.to_string()); | ||
redis_simple_string result; | ||
result.is_error = true; | ||
result.message = std::string("ERR ") + ec.to_string(); | ||
reply_message(entry, result); | ||
} else { | ||
::dsn::apps::incr_response incr_resp; | ||
::dsn::unmarshall(response, incr_resp); | ||
if (incr_resp.error != 0) { | ||
redis_simple_string result; | ||
result.is_error = true; | ||
result.message = "ERR internal error " + std::to_string(incr_resp.error); | ||
reply_message(entry, result); | ||
} else { | ||
redis_integer result; | ||
result.value = incr_resp.new_value; | ||
reply_message(entry, result); | ||
} | ||
} | ||
}; | ||
dsn::apps::incr_request req; | ||
pegasus_generate_key(req.key, entry.request.buffers[1].data, dsn::blob()); | ||
req.increment = increment; | ||
client->incr(req, on_incr_reply, std::chrono::milliseconds(2000), 0, pegasus_key_hash(req.key)); | ||
} | ||
|
||
void redis_parser::parse_set_parameters(const std::vector<redis_bulk_string> &opts, | ||
int &ttl_seconds) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.