-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
redis scan command support #678
base: master
Are you sure you want to change the base?
Conversation
r->max_server_idx=(pool->server).nelem; | ||
}else{ | ||
idx = server_pool_idx(pool, key, keylen); | ||
} |
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.
Change the cursor of request in req_filter
and save the server_index
on msg in the mean time.
src/proto/nc_redis.c
Outdated
@@ -3053,6 +3069,46 @@ redis_post_coalesce_mget(struct msg *request) | |||
} | |||
} | |||
|
|||
void redis_post_coalesce_scan(struct msg *request) { |
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.
move those code in rsp_filter
src/proto/nc_redis.c
Outdated
@@ -2963,6 +2976,9 @@ redis_fragment(struct msg *r, uint32_t nserver, struct msg_tqh *frag_msgq) | |||
case MSG_REQ_REDIS_MSET: | |||
return redis_fragment_argx(r, nserver, frag_msgq, 2); | |||
|
|||
case MSG_REQ_REDIS_SCAN: | |||
return redis_fragment_scan(r,frag_msgq); |
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.
The scan command doesn't need fragment, the thing you want do is change the cursor, you can do this in req_filter
.
When response received you need change the cursor again, you can do this in rsp_filter
.
src/nc_server.h
Outdated
@@ -137,7 +137,7 @@ void server_connected(struct context *ctx, struct conn *conn); | |||
void server_ok(struct context *ctx, struct conn *conn); | |||
|
|||
uint32_t server_pool_idx(const struct server_pool *pool, const uint8_t *key, uint32_t keylen); | |||
struct conn *server_pool_conn(struct context *ctx, struct server_pool *pool, const uint8_t *key, uint32_t keylen); | |||
struct conn *server_pool_conn(struct context *ctx, struct server_pool *pool, const uint8_t *key, uint32_t keylen, struct msg *msg); |
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.
I think put msg
in front of key and keylen is better.
src/nc_server.c
Outdated
nc_memcpy(key,arr,keylen); | ||
} | ||
r->scan_server_idx=idx; | ||
r->max_server_idx=(pool->server).nelem; |
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.
I think max_server_idx
is unnecessary, since you can always known the number of server by array_n(&pool->server)
.
Hi @wy-ei , I have re-committed according to your suggestion, thanks. |
src/nc_request.c
Outdated
@@ -511,6 +520,31 @@ req_filter(struct conn *conn, struct msg *msg) | |||
msg->noforward = 1; | |||
} | |||
|
|||
if (msg->type == MSG_REQ_REDIS_SCAN) { | |||
ASSERT(array_n(msg->keys) > 0); |
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.
move this into a function and call the function here like what you did in rsp_filter
.
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.
Good advice
@@ -300,6 +301,8 @@ struct msg { | |||
unsigned fdone:1; /* all fragments are done? */ | |||
unsigned swallow:1; /* swallow response? */ | |||
unsigned redis:1; /* redis? */ | |||
|
|||
uint32_t server_index; /* used for store the redis server index in server pool */ | |||
}; |
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.
this comment is not clear enough. how about this one:
the server index which the requstion should be forwarded.
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.
this comment is not clear enough. how about this one:
the server index which the requstion should be forwarded.
ok
@lukexwang I have see the change you made. it's better. And I think the code can be optimized again. I have leave some more suggestions. |
Hi @wy-ei , thank you for your suggestion. I have re-committed. |
Hello @wy-ei , 空了辛苦看下哈 ^_^ |
马晓栋已经收到您的来件,谢谢!
|
redis script command support
…add-scan-support
Problem
redis scan command not support.
Solution
Note:
server_idx
is saved by the lowest 12 bits of cursor, so the number of servers of the twemproxy must be less than 4096.Result