-
Notifications
You must be signed in to change notification settings - Fork 56
feat: support command cas, stats $memc_value #34
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
Open
syzh
wants to merge
2
commits into
openresty:master
Choose a base branch
from
syzh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -36,6 +36,7 @@ static ngx_str_t ngx_http_memc_cmd = ngx_string("memc_cmd"); | |
static ngx_str_t ngx_http_memc_value = ngx_string("memc_value"); | ||
static ngx_str_t ngx_http_memc_flags = ngx_string("memc_flags"); | ||
static ngx_str_t ngx_http_memc_exptime = ngx_string("memc_exptime"); | ||
static ngx_str_t ngx_http_memc_unique_token = ngx_string("memc_unique_token"); | ||
|
||
|
||
static ngx_int_t ngx_http_memc_add_more_variables(ngx_conf_t *cf); | ||
|
@@ -68,6 +69,7 @@ ngx_http_memc_handler(ngx_http_request_t *r) | |
ngx_http_variable_value_t *value_vv; | ||
ngx_http_variable_value_t *flags_vv; | ||
ngx_http_variable_value_t *exptime_vv; | ||
ngx_http_variable_value_t *unique_token_vv; | ||
|
||
ngx_http_memc_cmd_t memc_cmd; | ||
ngx_flag_t is_storage_cmd = 0; | ||
|
@@ -257,9 +259,14 @@ ngx_http_memc_handler(ngx_http_request_t *r) | |
u->input_filter_init = ngx_http_memc_empty_filter_init; | ||
u->input_filter = ngx_http_memc_empty_filter; | ||
|
||
} else if (memc_cmd == ngx_http_memc_cmd_version | ||
|| memc_cmd == ngx_http_memc_cmd_stats) | ||
{ | ||
} else if (memc_cmd == ngx_http_memc_cmd_stats) { | ||
u->create_request = ngx_http_memc_create_stats_cmd_request; | ||
u->process_header = ngx_http_memc_process_simple_header; | ||
|
||
u->input_filter_init = ngx_http_memc_empty_filter_init; | ||
u->input_filter = ngx_http_memc_empty_filter; | ||
|
||
} else if (memc_cmd == ngx_http_memc_cmd_version) { | ||
u->create_request = ngx_http_memc_create_noarg_cmd_request; | ||
u->process_header = ngx_http_memc_process_simple_header; | ||
|
||
|
@@ -344,6 +351,7 @@ ngx_http_memc_handler(ngx_http_request_t *r) | |
|
||
if (is_storage_cmd | ||
|| memc_cmd == ngx_http_memc_cmd_incr | ||
|| memc_cmd == ngx_http_memc_cmd_stats | ||
|| memc_cmd == ngx_http_memc_cmd_decr) | ||
{ | ||
value_vv = ngx_http_get_indexed_variable(r, mmcf->value_index); | ||
|
@@ -376,6 +384,33 @@ ngx_http_memc_handler(ngx_http_request_t *r) | |
ctx->memc_value_vv = value_vv; | ||
} | ||
|
||
if (memc_cmd == ngx_http_memc_cmd_cas) { | ||
unique_token_vv = ngx_http_get_indexed_variable(r, mmcf->unique_token_index); | ||
if (unique_token_vv == NULL) { | ||
return NGX_HTTP_INTERNAL_SERVER_ERROR; | ||
} | ||
|
||
if (unique_token_vv->not_found || unique_token_vv->len == 0) { | ||
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
"the \"$memc_unique_token\" variable is required for " | ||
"command \"%V\"", &ctx->cmd_str); | ||
|
||
return NGX_HTTP_BAD_REQUEST; | ||
} | ||
|
||
if (!ngx_http_memc_valid_uint32_str(unique_token_vv->data, | ||
unique_token_vv->len)) | ||
{ | ||
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
"variable \"$memc_unique_token\" takes invalid value: %v", | ||
unique_token_vv); | ||
|
||
return NGX_HTTP_BAD_REQUEST; | ||
} | ||
|
||
ctx->memc_unique_token_vv = unique_token_vv; | ||
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. Needs a blank line before this line. |
||
} | ||
|
||
rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); | ||
|
||
if (rc == NGX_ERROR || rc > NGX_OK) { | ||
|
@@ -512,6 +547,11 @@ ngx_http_memc_init(ngx_conf_t *cf) | |
return NGX_ERROR; | ||
} | ||
|
||
mmcf->unique_token_index = ngx_http_memc_add_variable(cf, &ngx_http_memc_unique_token); | ||
if (mmcf->unique_token_index == NGX_ERROR) { | ||
return NGX_ERROR; | ||
} | ||
|
||
return ngx_http_memc_add_more_variables(cf); | ||
} | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: needs a blank line before
} else if ...
.